Ruby on Rails Friday, July 2, 2010

I'd like to display a banner on every page. Ultimately I'll be tweaking
which banner is displayed via different controllers but initially I'd
just like to set a single banner application wide and display it in my
"_header", a partial I include in all layouts.

I've got a BannerAdvert model, simple. If I'm in my welcome controller
index action I can simply do,

@banner_url = BannerAdvert.first.url

in my _header partial (view) I display the url, works fine.

-----

BUT - my header is called from other controllers, I don't want to be
non-dry and repeat @banner_url = BannerAdvert.first.url all over the
place.

I'd like to set @banner_url = BannerAdvert.first.url application wide
for now - how do I do this, should be easy but I'm having a Friday
afternoon mental block! I thought application_controller and
application_helper, but putting the code in either of those two didn't
work.

Please help cure my insanity, any inspiration really appreciated.
--
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@googlegroups.com.
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.

No comments:

Post a Comment