On 22 August 2010 05:56, Chris <cdellin...@gmail.com> wrote: > I'm new to Rails and trying to figure out the correct way to handle > dynamic data in a partial. The partial in question will be used to > display a google ad. The html for this ad will differ based upon the > user (do they pay to not see ads, what the format/style of the ad will > look like needs to match the look and feel they have configured for > their profile, etc.). > > I was looking to place an ad in a view as follows: > > <%= render "shared/ad_banner", :ad_type => "120x90"%> > > where the ad type basically specifies what size ad the ad_banner > partial needs to render. The different html for the ads are stored in > a database. My question is can/should the partial do a lookup to > figure out what ad html to render based upon the ad_type passed in > (along with information about the currently logged in user)? Or should > the actual lookup occur in the controller and the html be passed into > the partial? My first thought was it would be cleaner if I had the > partial do the lookup since the controller would not have to have any > knowledge about what size ad needs to be rendered, this information > was basically embedded in the view. > > However, when trying to figure out how to make the partial do the > lookup I started wondering if this was bad form based upon the lack of > examples I saw for this type of approach (all the examples seemed to > be passing the data in).
My thought would be that the view code should preferably not be looking up stuff. The controller should provide (via @ variables) all the data that it needs. However, if you are talking about the size of something on display this should certainly not be defined in the controller. The controller should not say 'display this at a certain size', but should provide whatever data the view needs in order that it can decide the size. In fact generally the size would be in css with the view just setting up classes so even the view does not have to know the size or layout. Colin -- 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-t...@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.