I have a very n00b question about Rails. What are the variables and methods available to a view in Rails? I had a problem today, from working on an existing project, where a method was missing from our my_model_helper.rb file. I didn’t even know that methods in a _helper.rb were available.
I know, for example, that any instance variables from the controller are available from the view, but that’s the limit of my knowledge.
Thanks!
You’ve already named what’s available in views: instance variables defined in the controller and helpers. Helpers can be defined in
_helper.rb-files and inside controllers as regular methods but you have to mark them withhelper_method(link).Of course, methods defined in
_helper.rbare available in any view but controller’s helpers are available ONLY for views that are rendered with this controller.I hope you already know about
params,request,response,sessionand other core-methods to access/manipulate the state of user’s request/response.