szimek
2010-Apr-24 06:45 UTC
Would it be possible to add procs to route definition to set params when generating a route?
Hey, in my current project I need to provide a city name as a prefix in *most* of urls in my app, which acts as a scope for permalinks. I''d like to avoid manually passing city name to almost every link_to and redirect_to if possible. Would it be possible to add to Rails 2.3/3.0 routing system something similar to default param values, but to actually set these values using a proc? I.e. for locales you could do something like: map.with_options :path_prefix => "/:locale", :locale => Proc.new { | params| params[:locale] = I18n.locale } do |locale| locale.resources .... end This would require some changes to *_url helpers, so that it wouldn''t try to assign the first attribute passed to the helper to :locale param. I''m not sure in what context these procs could be evaluated and what variables could be passed to them. I know that there''s routiing-filter plugin by Sven Fuchs, but it works for all routes. Additionally, having a route like "/posts/:category/:id" - currently you have to pass "post.category" manually as the first param - with this addition you could do something like: map.post "/posts/:category/:id". :category => Proc.new { |params| params[:category] = params[:id].category } so that stuff like link_to(post.title, post) would still work. Any tips if it''s even possible to implement something like this with the Rails 2.3/3.0 routing system? Regards, Szymon -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Core" group. To post to this group, send email to rubyonrails-core@googlegroups.com. To unsubscribe from this group, send email to rubyonrails-core+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-core?hl=en.