is it necessary to mention the private methods in controller as helper_methods
in controller?
Like
class PostsController < ApplicationController
helper_method :check_something
def new
check_something
@post = Post.new
end
def show
@post = Post.find(params[:id])
end
private
def check_something
redirect_to(root_path) and return if something
end
end
Is the statement : helper_method :check_something
required ? if so why ?
And when i call a private method from a controllers action method is the params
hash accessible in the private or the helper
method ??
I think you have misunderstood the 'helper_method' concept.
helper_method
is used to make your controller method to act as a method as its in your helper modules
So inside your controller, you can always access your private method without the 'helper_method
' section
and if you add a controller method as a helper method, as you have already done, in your view you can simply call it
and for your second question, yes params hash is accessible via controllers private methods
HTH
No it is not necessary. You can always call private
methods of your controller within your controller.
Also, params
would be available automatically for the private
methods within controller.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With