I have a menu_items array (array of hashes, with printed name and url for each item) in a helper, which i use to create my mainmenu. I''d like to use them in routes.rb so i can loop through them and map routes according to their names. Is there a way to do so? Or should i set this up in a different way? --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
You might be able to do this with at least one of change. Since the essence of routing is matching a (named) url with the controller/ action that needs to respond to it, you''ll need to add info to your hash. Armed with that you might be able to do something like (untested): MenuItemHelper::MENU.each do |menu_mapping| map.send menu_mapping[:name], menu_mapping[:url], :controller=>menu_mapping[:controller], :action=>menu_mapping[:action] end HTH, AndyV On Feb 13, 8:03 pm, Peter <peterdun...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have a menu_items array (array of hashes, with printed name and url > for each item) in a helper, which i use to create my mainmenu. I''d > like to use them in routes.rb so i can loop through them and map > routes according to their names. Is there a way to do so? Or should i > set this up in a different way?--~--~---------~--~----~------------~-------~--~----~ 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 that would be helperclass::methodname.each to get access to the correct array. Thank you, that''s what i needed. But what exactly does map.send do here? i assume this command translates for each item into something like ''map.connect ''"action", :controller => etc etc'' ? or does map.send do something xompletely different? (i don''t see the ''connect'' in your example) On Feb 14, 9:41 pm, AndyV <a...-HmMyXyqgL2CVc3sceRu5cw@public.gmane.org> wrote:> You might be able to do this with at least one of change. Since the > essence of routing is matching a (named) url with the controller/ > action that needs to respond to it, you''ll need to add info to your > hash. Armed with that you might be able to do something like > (untested): > > MenuItemHelper::MENU.each do |menu_mapping| > map.send menu_mapping[:name], > menu_mapping[:url], :controller=>menu_mapping[:controller], :action=>menu_mapping[:action] > end > > HTH, > AndyV > > On Feb 13, 8:03 pm, Peter <peterdun...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > I have a menu_items array (array of hashes, with printed name and url > > for each item) in a helper, which i use to create my mainmenu. I''d > > like to use them in routes.rb so i can loop through them and map > > routes according to their names. Is there a way to do so? Or should i > > set this up in a different way?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Have a look at this episode from Railscasts. I''ve used this many times now to use a lot of my ''brochureware'' style pages that aren''t really resources that fit inside the REST ideas. I usually create one controller to deal with all that static content and then use this idea from railscasts to just map a whole bunch of them with named routes. hope this helps: http://railscasts.com/episodes/79 On Feb 17, 3:42 am, Peter <peterdun...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> So that would be helperclass::methodname.each to get access to the > correct array. Thank you, that''s what i needed. But what exactly does > map.send do here? i assume this command translates for each item into > something like ''map.connect ''"action", :controller => etc etc'' ? or > does map.send do something xompletely different? (i don''t see the > ''connect'' in your example) > > On Feb 14, 9:41 pm, AndyV <a...-HmMyXyqgL2CVc3sceRu5cw@public.gmane.org> wrote: > > > You might be able to do this with at least one of change. Since the > > essence of routing is matching a (named) url with the controller/ > > action that needs to respond to it, you''ll need to add info to your > > hash. Armed with that you might be able to do something like > > (untested): > > > MenuItemHelper::MENU.each do |menu_mapping| > > map.send menu_mapping[:name], > > menu_mapping[:url], :controller=>menu_mapping[:controller], :action=>menu_mapping[:action] > > end > > > HTH, > > AndyV > > > On Feb 13, 8:03 pm, Peter <peterdun...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > I have a menu_items array (array of hashes, with printed name and url > > > for each item) in a helper, which i use to create my mainmenu. I''d > > > like to use them in routes.rb so i can loop through them and map > > > routes according to their names. Is there a way to do so? Or should i > > > set this up in a different way?--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---