Is there a way to write a method in the application controller and also
have it available as a helper method without rewriting it in the
application helper?
I’m pretty sure there is, but haven’t found the specifics on how to do
this yet.
Is there a way to write a method in the application controller and also
have it available as a helper method without rewriting it in the
application helper?
I’m pretty sure there is, but haven’t found the specifics on how to do
this yet.
Is it possible to have method(s) in application_helper.rb available
for controllers, just like for views?
Actually my method is current_user too and looks pretty similar,
but I’d like it in application_helper.rb…
Is it possible to have method(s) in application_helper.rb available
for controllers, just like for views?
Actually my method is current_user too and looks pretty similar,
but I’d like it in application_helper.rb…
define the method in your helper, then include your helper at the top of
the controller:
class ApplicationHelper
def method_to_use_in_controller
…
end
end
class ApplicationController
include ApplicationHelper
end
that’s the easiest way to do it … but if you have a lot of methods in
your ApplicationHelper you may want to pull it out into a module that
gets included into both the helper and controller.