Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

[PATCH] Allow to use procs when specifying defaults for routes

#4737

Hey,

with this patch it's possible to do something like this:

get ":locale/:book/pages/:page(/:version)" => "pages#show",
    :as => :page,
    :defaults => { :locale => Proc.new { I18n.locale }, :page => 1 }

page_path("catch-22", 5, 1) => "/en/catch-22/pages/5/1"
page_path("catch-22", :locale => :pl) => "/pl/catch-22/pages/1"

scope "/:locale", :defaults => { :locale => Proc.new { I18n.locale } } do
  resources :page
end

pages_path => "/en/pages"
pages_path(:locale => :pl) => "/pl/pages"

I couldn't figure out how to pass current controller instance or parameters to defaults block, but I guess it's going to be useful anyway.

I'm attaching a patch and a file that can be put i.e. into config/initializers to get this functionality without patching Rails.

Reported by Szymon Nowak · May 31st, 2010 @ 01:44 PM

State: stale
Milestone: none
Assigned to: josh josh
Importance: none

Activity

  1. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:52 PM

  2. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:52 PM