Well, I know it should not be asked here, But I did not find a better place to get answer. This question was asked in a good company's interview.
In Rails MVC, can you call a controller's method from a view (as we call from helper ideally) ? If yes, how?
I couldn't answer that question that time. Would you please help?
Here is the answer:
Then, in your view, you can reference it in ERB exactly how you expect with
<%
or<%=
:make your action helper method using
helper_method :your_action_name
Or you can also make all actions as your helper method using:
helper :all
In both cases, you can access foo and bar from all controllers.
Haven't ever tried this, but calling public methods is similar to:
and private methods:
See more details here
You possibly want to declare your method as a "helper_method", or alternatively move it to a helper.
What do helper and helper_method do?