Hi I am starting to work with rails and like to build a very basic cms. I was using scaffolding. Page title:string permalink:string body:text. What I like to do is create a menu out of the database entries permalink. Those should link to the fitting pages. So i modified my index.html.erb from the pages view like this: <% @pages.each do |page| %> <%= link_to_unless_current page.permalink, page_path(page) %> <% end %> I like to use something like the code above in a div layer as a menu and link the result to the div layer were the <% yield %> is placed. I was trying to do this with helper module and also with partials, but I couldnt solve this. Do I need ajax? or is there a way to do it with rails only? Maybe someone has a good tip? Best regards dlc --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
On Sep 28, 10:31 am, dlc <betabet...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote:> Hi > > I am starting to work with rails and like to build a very basic cms. > > I was using scaffolding. > Page title:string permalink:string body:text. > > What I like to do is create a menu out of the database entries > permalink. > Those should link to the fitting pages. > > So i modified my index.html.erb from the pages view like this: > > <% @pages.each do |page| %> > <%= link_to_unless_current page.permalink, page_path(page) %> > <% end %> > > I like to use something like the code above in a div layer as a menu > and link the result to the div layer were the <% yield %> is placed. > > I was trying to do this with helper module and also with partials, but > I couldnt solve this. > Do I need ajax? or is there a way to do it with rails only? > > Maybe someone has a good tip? > > Best regards > > dlcIn ./app/helpers/application_helper.rb: def tab_for(name, href, html_options = {} ) #puts ''tab'', @current_tab.to_s, ''href'', href.to_s if @current_tab.to_s.starts_with?(href.to_s.downcase) #content_tag :span, name, html_options html_options.merge!(:class => ''active'') link_to name, href, html_options else link_to name, href, html_options end end In the view layout: <ul id="mnav"> <li><%= tab_for ''Directories'', directories_path %></li> <li><%= tab_for ''Software'', softwares_path %></li> </ul> The tab_for function does a match on the request path to determine if its active or not...works well for single level menus, but would need modification to support sub menus. --~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi, thanks a lot. I try to work that out. Best Daniel On Sep 28, 9:26 pm, chovy <ettin...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sep 28, 10:31 am, dlc <betabet...-gM/Ye1E23mwN+BqQ9rBEUg@public.gmane.org> wrote: > > > > > Hi > > > I am starting to work with rails and like to build a very basic cms. > > > I was using scaffolding. > > Page title:string permalink:string body:text. > > > What I like to do is create amenuout of the database entries > > permalink. > > Those should link to the fitting pages. > > > So i modified my index.html.erb from the pages view like this: > > > <% @pages.each do |page| %> > > <%= link_to_unless_current page.permalink, page_path(page) %> > > <% end %> > > > I like to use something like the code above in a div layer as amenu > > and link the result to the div layer were the <% yield %> is placed. > > > I was trying to do this with helper module and also with partials, but > > I couldnt solve this. > > Do I need ajax? or is there a way to do it with rails only? > > > Maybe someone has a good tip? > > > Best regards > > > dlc > > In ./app/helpers/application_helper.rb: > > def tab_for(name, href, html_options = {} ) > #puts ''tab'', @current_tab.to_s, ''href'', href.to_s > if @current_tab.to_s.starts_with?(href.to_s.downcase) > #content_tag :span, name, html_options > html_options.merge!(:class => ''active'') > link_to name, href, html_options > else > link_to name, href, html_options > end > end > > In the view layout: > > <ul id="mnav"> > <li><%= tab_for ''Directories'', directories_path %></li> > <li><%= tab_for ''Software'', softwares_path %></li> > </ul> > > The tab_for function does a match on the request path to determine if > its active or not...works well for single level menus, but would need > modification to support sub menus.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Actually got a good bit of code for this done. 1. Scan a available controllers, and add table entries for any "new" ones automatically 2. If updates, generate new tabnav menus automatically at startup. I use widgets for my menu, and do nesting to multiple levels. Since I tend to use namespaces as well for different major functions, a lot of "assumptions" can be made based on controller location and name. The nice thing is you can then "edit" the table, and regenerate the tabnav menu. If your interested, shout, I''ll go dig up the code. I use ActiveScaffold, and Widgets/Tabnav for my sites. On top of that, I use some ruby code to glue it to a database table. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Hi, glennswest wrote>> > Actually got a good bit of code for this done. > > 1. Scan a available controllers, and add table entries for any "new" > ones automatically > 2. If updates, generate new tabnav menus automatically at startup.Sounds like a good candidate for a plugin! Let us know if you go there. Best regards, Bill --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---