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

发布于 2024-10-09 02:49:01 字数 2857 浏览 0 评论 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) 的东西,它运行得很好......在上述更改之后,此网址不再正确生成,并给出以下错误:

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')}

我真诚地感谢任何人能够提供有关处理此类事情的正确方法和/或为什么此网址不再生成的任何见解,谢谢!

I'm localizing my application and am struggling with how to handle routes for a specific portion of the app.

Initially I had routes that looked like this:


    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

From what I've done successfully on other routes I need to add: :path_prefix => '/:locale/' to these routes.

The only example I've come across looks something like this:

  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

This actually appears works great for the routes, however, it is screwing up some of my generated URLS.

For example previously I had something like = link_to(t('subscription'), edit_admin_subscription_path(subscription_id) which worked perfectly... after the above change this url no longer properly generates, giving the following error:

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')}

I would sincerely appreciate any insight anyone can shed on the proper way to handle this type of thing and/or why this url doesn't like to generate any longer. THANKS!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

审判长 2024-10-16 02:49:01

因此,在添加本地化之后,我需要更具体地了解传递到 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|

最好的方法,但至少现在是有效的。

So as it turns out after the addition of the localization, I needed to be more specific with the the parameters passed into the URL helper:

= link_to(t('subscription'), edit_admin_subscription_path(:id => subscription_id) works just fine.

Still not sure not certain if the


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

is the best way to do that, but at least it's working for now.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文