Rails - 为路线添加范围打破了Friendy Urls

时间:2017-02-24 14:09:21

标签: ruby-on-rails ruby friendly-url globalize

我最近在我的路线中添加了本地化范围(如Railscasts PRO#138中所述),因为我需要它们看起来像这样:

localhost/en/admin/posts
localhost/en/admin/posts/happy-new-post/edit

但添加范围会引发错误: can't find record with friendly id: "posts" 这是我的参数在这种情况下的看法:

Request

Parameters:

{"page_category_id"=>"admin", "id"=>"posts"}

这是我的config / routes.rb的样子:

Rails.application.routes.draw do



  # For details on the DSL available within this file, see http://guides.rubyonrails.org/routing.html

  scope ":locale", locale: /#{I18n.available_locales.join("|")}/ do
    namespace :admin do
        get '', to: 'dashboard#index', as: '/'

      namespace :settings do
        get '', to: 'dashboard#index', as: '/'
        resources :general_settings, except: :show
      end
        resources :pages, except: :show
      resources :posts, except: :show
      resources :page_categories, except: :show
      resources :post_categories, except: :show
      resources :users, except: :show
    end
  end
end

如果有帮助,这是我的Post-model:

class Post < ApplicationRecord

  include Bootsy::Container
  belongs_to :post_category

  validates :title, presence: true

  extend FriendlyId
  friendly_id :title, use: [:finders, :slugged]

  translates :title, :body
  globalize_accessors :locales => [:en, :ru], :attributes => [:title, :body]
end

有没有办法制作像localhost/en/admin/posts/happy-new-post/edit这样的网址?

0 个答案:

没有答案