In Rails MVC, can you call a controller's method from a view (as a method could be called call from a helper)? If yes, how?
Asked
Active
Viewed 7.9k times
4 Answers
23
You possibly want to declare your method as a "helper_method", or alternatively move it to a helper.
9
make your action helper method using helper_method :your_action_name
class ApplicationController < ActionController::Base
def foo
# your foo logic
end
helper_method :foo
def bar
# your bar logic
end
helper_method :bar
end
Or you can also make all actions as your helper method using: helper :all
class ApplicationController < ActionController::Base
helper :all
def foo
# your foo logic
end
def bar
# your bar logic
end
end
In both cases, you can access foo and bar from all controllers.

przbadu
- 5,769
- 5
- 42
- 67