<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> </head> <body bgcolor="#ffffff" text="#000000"> <font size="-1"><font face="Helvetica, Arial, sans-serif">I have an app that does a number of collection_selects. There are two general methods of getting the data and displaying it that I am aware of.<br> <br> You can do a find in the controller and assign the result to an instance variable and do the collection_select stuff in the view.<br> <br> Alternatively you can put the whole find and collection_select in the view (in erb of course).<br> <br> To me it seems to clutter up the view to do the find in the view so I prefer it in the controller. Is there some reason that it would be better to do it all in the view? <br> <br> I am looking for opinions here on the ''best practice'' or does it not matter?<br> <br> Thanks<br> Norm<br> </font></font> </body> </html> <p></p> -- <br /> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.<br /> To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org<br /> To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org<br /> For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.<br />
Norm Scherer wrote:> Is there some reason that it would be > better to do it all in the view?No. Ideally, the view is only the presentation layer. Among other reasons, when you start reusing partials, it will be come readily apparent why you want to marshal the data in the controller, and make it available to the view. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Ar Chron wrote:> Norm Scherer wrote: >> Is there some reason that it would be >> better to do it all in the view? > > No. > > Ideally, the view is only the presentation layer. > > Among other reasons, when you start reusing partials, it will be come > readily apparent why you want to marshal the data in the controller, and > make it available to the view.Right. The view never, ever, ever touches the database. If you think you want it to do so, you''ve got a design problem. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
a tip when using partials: look into :locals option and use it extensively. Don''t assume that a partial can "see" things from the controller - specify what you want the partial to see using :locals. It''ll pay off in the end. On Jun 22, 10:39 am, Marnen Laibow-Koser <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Ar Chron wrote: > > Norm Scherer wrote: > >> Is there some reason that it would be > >> better to do it all in the view? > > > No. > > > Ideally, the view is only the presentation layer. > > > Among other reasons, when you start reusing partials, it will be come > > readily apparent why you want to marshal the data in the controller, and > > make it available to the view. > > Right. The view never, ever, ever touches the database. If you think > you want it to do so, you''ve got a design problem. > > Best, > -- > Marnen Laibow-Koserhttp://www.marnen.org > mar...-sbuyVjPbboAdnm+yROfE0A@public.gmane.org > -- > Posted viahttp://www.ruby-forum.com/.-- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
chewmanfoo wrote:> a tip when using partials: look into :locals option and use it > extensively. Don''t assume that a partial can "see" things from the > controller - specify what you want the partial to see using :locals. > It''ll pay off in the end.A most excellent tip. :object and :collection are also very helpful. Best, -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.