开发者

What objects are passed into the view?

开发者 https://www.devze.com 2023-01-21 03:07 出处:网络
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!

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

0

精彩评论

暂无评论...
验证码 换一张
取 消