What objects are passed into the view?
I'm guessing all objects that are local to the action are passed into the view?
I never see sample code that actually specifies which objects are passed to the view!
Is it good practice to create a 'model' object and then assign, as properties to开发者_JS百科 the 'model' object, all objects you want to pass to the view?
How can you explicitly pass objects?
Anything you put in an instance variable (e.g., @my_variable
) in the controller action is accessible to the view.
As far as passing model objects goes, just pass a model if you need to. But there's no need to create a "view model" object like (say) ASP.NET MVC pretty much makes you do. :-)
It's all instance attribute of Controller to pass to view
There are multiple ways in which you can access them. If you are just using something like
render :template
, you are pretty much ok with having any instance variable(something that looks like @object
). If you are say rendering partials, you can pass in as render :partial => 'x', :locals => {:object_name => local_variable}
. The guides on rubyonrails site has pretty much what is required to do rendering on views -> http://guides.rubyonrails.org/layouts_and_rendering.html
精彩评论