I have a series of ''static'' pages for a site that need named routes in Rails 3. I''m trying to DRY the routes file, but can''t seem to find the proper code. The desired output/code is: match ''/about'' => ''info#about'', :as => :about for each page. My attempt to dry this: %w(about services articles marketing clients).each do |page| match eval( "''/#{page}'' => ''info##{page}'', :as => :#{page}") end Any suggestions? -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I figured this out: eval( "match ''/#{page}'' => ''info##{page}'', :as => :#{page}") On Jul 3, 10:37 pm, dwormuth <dworm...-cIpcPs7DjqbWs/AcZQh2Cw@public.gmane.org> wrote:> I have a series of ''static'' pages for a site that need named routes in > Rails 3. I''m trying to DRY the routes file, but can''t seem to find the > proper code. > > The desired output/code is: > > match ''/about'' => ''info#about'', :as => :about > > for each page. My attempt to dry this: > > %w(about services articles marketing clients).each do |page| > match eval( "''/#{page}'' => ''info##{page}'', :as => :#{page}") > end > > Any suggestions?-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
dwormuth wrote:> I have a series of ''static'' pages for a site that need named routes in > Rails 3. I''m trying to DRY the routes file, but can''t seem to find the > proper code. > > The desired output/code is: > > match ''/about'' => ''info#about'', :as => :about > > for each page. My attempt to dry this: > > %w(about services articles marketing clients).each do |page| > match eval( "''/#{page}'' => ''info##{page}'', :as => :#{page}") > endeval is almost never a good idea, and it certainly isn''t needed here. Try: match "/#{page}" => "info##{page}", :as => page.to_sym> > Any suggestions?Remember to try string interpolation and send. eval is not that useful in Ruby -- if you think you need it, remember that you almost certainly don''t. -- Marnen Laibow-Koser http://www.marnen.org marnen-sbuyVjPbboAdnm+yROfE0A@public.gmane.org Sent from my iPhone -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.