问题
I have nested routes for a has_many and belongs_to relationship.
resources :websites, :path => 'w' do
resources :pages, :path => ''
end
I'm using friendly ID gem to replace the page ID in the URL with a slug.
So my URLs look like this
http://example.com/w/1-website-name/page-name
However, when a duplicate page name is added, friendly ID appends a random hash to it to make it unique, even if the page belongs to a different website.
Is there a way I can make it so page names only must be unique within the website they belong to?
I want to be able to do this:
http://example.com/w/1-website-one/home
and
http://example.com/w/2-website-two/home
回答1:
Adding scope might be an answer:
friendly_id :name, :use => :scoped, :scope => :website
来源:https://stackoverflow.com/questions/41923056/id-unique-to-nested-model-not-unique-globally