在Rails 2.3.8中处理本地化名称间隔路由的正确方法是什么?

时间:2010-12-20 20:28:26

标签: ruby-on-rails localization routing routes ruby-on-rails-2

我正在本地化我的应用程序,并且正在努力处理应用程序特定部分的路由。

最初,我的路线看起来像这样:


    map.namespace :admin do |admin|
      admin.resources :people, :member => {:confirm_destroy => :get}, :collection => {:follow => :post, :sync_friends => :get, :upload => :post, :import => :get, :recommendations => :get, :mark_recommendations => :post, :batch_create => :post}
      admin.resources :jobs, :collection => {:remove => :post}
      admin.resources :users, :member => {:confirm_destroy => :get}
      admin.resources :sites, :member => {:update_design => :post, :design => :get, :update_links => :post, :links => :get, :content => :get, :update_content => :post, :add_admin => :post, :remove_admin => :post, :set_system_account => :get, :confirm_system_account => :get}, :collection => {:remove => :post, :upload => :post}
      admin.resources :subscriptions, :member => { :charge => :post, :migrate_plan => :post, :update_components => :post }
      admin.resources :accounts, :collection => {:remove => :post}
      admin.resources :subscription_plans, :as => 'plans'
      admin.resources :subscription_discounts, :as => 'discounts'
      admin.resources :twitter_lists, :collection => {:auto_generate_twitter_list => :post}
    end

从我在其他路线上成功完成的工作,我需要为这些路线添加:path_prefix => '/:locale/'

我遇到的唯一例子看起来像这样:

  map.with_options(:path_prefix => '/:locale/admin') do |locale|
    locale.namespace :admin do |admin|
      admin.resources :people, :member => {:confirm_destroy => :get}, :collection => {:follow => :post, :sync_friends => :get, :upload => :post, :import => :get, :recommendations => :get, :mark_recommendations => :post, :batch_create => :post}
      admin.resources :subscriptions, :member => { :charge => :post, :migrate_plan => :post, :update_components => :post }
      admin.resources :accounts, :collection => {:remove => :post}
      etc etc etc
    end
  end

这实际上看起来非常适合路由,但是,它会搞砸我生成的一些URL。

例如,之前我有= link_to(t('subscription'), edit_admin_subscription_path(subscription_id)这样的东西完美地工作......在上述更改后,此网址不再正常生成,发出以下错误:

ActionController::RoutingError in Admin/base#index

Showing app/views/admin/shared/_menu.html.haml where line #13 raised:

edit_admin_subscription_url failed to generate from {:action=>"edit", :controller=>"admin/subscriptions", :locale=>BSON::ObjectId('4d0ecb6587adddc91c000014')}, expected: {:controller=>"admin/subscriptions", :action=>"edit"}, diff: {:locale=>BSON::ObjectId('4d0ecb6587adddc91c000014')}

我真诚地感谢任何人都可以找到处理此类事情的正确方法的任何见解和/或为什么这个网址不再生成。谢谢!

1 个答案:

答案 0 :(得分:0)

因此,在添加本地化之后,我需要更具体地使用传递给URL帮助程序的参数:

= link_to(t('subscription'), edit_admin_subscription_path(:id => subscription_id)效果很好。

仍然不确定是否确定


  map.with_options(:path_prefix => '/:locale/admin') do |locale|
    locale.namespace :admin do |admin|

是最好的方法,但至少它现在正在运作。