Jamie
2009-Nov-16 21:19 UTC
Displaying information from one model on all views in an application
I''ve created a model that I plan to use to store messages that I want to be broadcast on every page of my application. I''m storing the message text, a class name for css styling, and a start and end timestamp that I want it to display between. I was trying to find a way to insert these items into my application.html.erb layout template so that I don''t have to include something in every single view. There is also a controller set up for the message items. Hopefully someone can help me with this, let me know if you need any more info.
eugenio
2009-Nov-16 21:39 UTC
Re: Displaying information from one model on all views in an application
you can use a before_filter in the application controller. in the method called by before_filter fetch the data you want from the model and store the result in an instance variable, e.g. @message create a partial that use this @message variable and insert it in your application layout. On 16 Nov, 22:19, Jamie <james.white...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I''ve created a model that I plan to use to store messages that I want > to be broadcast on every page of my application. I''m storing the > message text, a class name for css styling, and a start and end > timestamp that I want it to display between. > > I was trying to find a way to insert these items into my > application.html.erb layout template so that I don''t have to include > something in every single view. There is also a controller set up for > the message items. Hopefully someone can help me with this, let me > know if you need any more info.
Darian Shimy
2009-Nov-16 22:29 UTC
Re: Displaying information from one model on all views in an application
Take a look here: http://railscasts.com/episodes/103-site-wide-announcements Darian Shimy -- http:/www.darianshimy.com http://twitter.com/dshimy On Mon, Nov 16, 2009 at 1:19 PM, Jamie <james.white138-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > I''ve created a model that I plan to use to store messages that I want > to be broadcast on every page of my application. I''m storing the > message text, a class name for css styling, and a start and end > timestamp that I want it to display between. > > I was trying to find a way to insert these items into my > application.html.erb layout template so that I don''t have to include > something in every single view. There is also a controller set up for > the message items. Hopefully someone can help me with this, let me > know if you need any more info. > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Jamie
2009-Nov-17 02:06 UTC
Re: Displaying information from one model on all views in an application
thanks guys, i''ll take a look On Nov 16, 5:29 pm, Darian Shimy <dsh...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Take a look here:http://railscasts.com/episodes/103-site-wide-announcements > > Darian Shimy > -- > http:/www.darianshimy.comhttp://twitter.com/dshimy > > > > On Mon, Nov 16, 2009 at 1:19 PM, Jamie <james.white...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I''ve created a model that I plan to use to store messages that I want > > to be broadcast on every page of my application. I''m storing the > > message text, a class name for css styling, and a start and end > > timestamp that I want it to display between. > > > I was trying to find a way to insert these items into my > > application.html.erb layout template so that I don''t have to include > > something in every single view. There is also a controller set up for > > the message items. Hopefully someone can help me with this, let me > > know if you need any more info.