I''m setting up a forum and I''m having a sidebar which will display the recent postings and will be used throughout the site. This sidebar is part of the application.rhtml layout. How do I use data from the "forum" controller in this layout when the layout is used on all of the other controllers across the site? Could someone point me in the right direction? Many thanks - when I get a little more advanced I hope I can contribute as much advice as you guys have so kindly given me :-) -- 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-/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 -~----------~----~----~----~------~----~------~--~---
I''d say the nicest/cleanest thing to do would be to set that sidebar to be populated via AJAX. When the page loads, send of a request to the forum controller and update the sidebar div. Jason On 12/18/06, Scott Holland <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > I''m setting up a forum and I''m having a sidebar which will display the > recent postings and will be used throughout the site. This sidebar is > part of the application.rhtml layout. > > How do I use data from the "forum" controller in this layout when the > layout is used on all of the other controllers across the site? > > Could someone point me in the right direction? > > Many thanks - when I get a little more advanced I hope I can contribute > as much advice as you guys have so kindly given me :-) > > -- > 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-/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 -~----------~----~----~----~------~----~------~--~---
Jason Roelofs wrote:> I''d say the nicest/cleanest thing to do would be to set that sidebar to > be > populated via AJAX. When the page loads, send of a request to the forum > controller and update the sidebar div. > > JasonThanks but AJAX is something on my list to learn after I''ve got ror under my belt! :) Is there any other way to do it with application_help, or by rendering partials etc? Thanks -- 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-/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 -~----------~----~----~----~------~----~------~--~---
Well, here''s all the code you would need to get the AJAX working: application.rhtml: ... <div id="sidebar"> <%= javascript_tag remote_function(:update => ''sidebar'', :url => {:controller => ''forum_controller'', :action => ''sidebar_action'' }) %> </div> I''m assuming the action on the forum controller already exists, and you''d just need a partial that renders just those items. However, if you really want a non-ajax format, I guess you would need a method on the Forum model (if you don''t already have that) and then in your application.rb you can have: class Application ... after_filter :fill_in_sidebar def fill_in_sidebar @sidebar_posts = Forum.find_newest_posts end end This will call #fill_in_sidebar after any action on any controller. Hope that helps. Jason On 12/18/06, Scott Holland <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > > Jason Roelofs wrote: > > I''d say the nicest/cleanest thing to do would be to set that sidebar to > > be > > populated via AJAX. When the page loads, send of a request to the forum > > controller and update the sidebar div. > > > > Jason > > Thanks but AJAX is something on my list to learn after I''ve got ror > under my belt! :) > > Is there any other way to do it with application_help, or by rendering > partials etc? > > Thanks > > -- > 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-/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 -~----------~----~----~----~------~----~------~--~---
Scott Holland wrote:> I''m setting up a forum and I''m having a sidebar which will display the > recent postings and will be used throughout the site. This sidebar is > part of the application.rhtml layout. > > How do I use data from the "forum" controller in this layout when the > layout is used on all of the other controllers across the site? > > Could someone point me in the right direction? > > Many thanks - when I get a little more advanced I hope I can contribute > as much advice as you guys have so kindly given me :-) > >Use a partial (perhaps in a /shared folder) and populate it with an instance variable set up in the application controller using a before_filter. So something like this _recent_postings_sidebar.rhtml <% @recent_posts.each do |post| %> <%= post.title %> <% end %> in the application controller :before_filter :setup_sidebar def setup_sidebar @recent_posts = Post.find(:all, :limit => 20, :order => "created_at DESC") end and then in your layout: render :partial => "/shared/recent_postings_sidebar" --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
scottholland300-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2006-Dec-23 22:53 UTC
Re: Using data in application.rhtml layout
On Dec 18, 6:37 pm, Chris T <ctmailingli...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Scott Holland wrote: > > I''m setting up a forum and I''m having a sidebar which will display the > > recent postings and will be used throughout the site. This sidebar is > > part of theapplication.rhtml layout. > > > How do I use data from the "forum" controller in this layout when the > > layout is used on all of the other controllers across the site? > > > Could someone point me in the right direction? > > > Many thanks - when I get a little more advanced I hope I can contribute > > as much advice as you guys have so kindly given me :-)Use a partial (perhaps in a /shared folder) and populate it with an > instancevariableset up in theapplicationcontroller using a > before_filter. > > So something like this > > _recent_postings_sidebar.rhtml > > <% @recent_posts.each do |post| %> > <%= post.title %> > <% end %> > > in theapplicationcontroller > :before_filter :setup_sidebar > > def setup_sidebar > @recent_posts = Post.find(:all, :limit => 20, :order => > "created_at DESC") > end > > and then in your layout: > > render :partial => "/shared/recent_postings_sidebar"That worked great on my local machine, but when I uploaded it to a server using fcgi the variable does not update once it has been initially set. Any ideas? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
> So something like this > > _recent_postings_sidebar.rhtml > > <% @recent_posts.each do |post| %> > <%= post.title %> > <% end %> > > in the application controller > :before_filter :setup_sidebar > > def setup_sidebar > @recent_posts = Post.find(:all, :limit => 20, :order => > "created_at DESC") > end > > and then in your layout: > > render :partial => "/shared/recent_postings_sidebar"This works great on my local machine, (using webrick) but when I use it on an apache fcgi server (dreamhost) the variable does not update after it has been initially set. Anyone have any ideas how to fix this? -- 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-/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 -~----------~----~----~----~------~----~------~--~---