0

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

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


    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)工作得很好......在上述更改后,此 url 不再正确生成,出现以下错误:

Admin/base#index 中的 ActionController::RoutingError

显示第 13 行引发的 app/views/admin/shared/_menu.html.haml:

edit_admin_subscription_url 无法从 {:action=>"edit", :controller=>"admin/subscriptions", :locale=>BSON::ObjectId('4d0ecb6587adddc91c000014')} 生成,预期:{:controller=>"admin/subscriptions ", :action=>"edit"}, 差异: {:locale=>BSON::ObjectId('4d0ecb6587adddc91c000014')}

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

4

1 回答 1

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|

是做到这一点的最好方法,但至少它现在正在工作。

于 2010-12-20T21:22:35.927 回答