How to use the slug from Friendly_id in a nested route?

时光毁灭记忆、已成空白 提交于 2021-02-08 05:38:15

问题


I am having a hard time making the slug from Friendly_id in a nested route when editing and creating? the routes look great for show.

http://0.0.0.0:3000/test/tester2

This is the URL I am getting when i try to edit tester2 is:

http://0.0.0.0:3000/2/tester2/edit

What i would like to see is:

http://0.0.0.0:3000/test/tester2/edit

Here is my code.

team.rb

class Team < ActiveRecord::Base
  extend FriendlyId
  friendly_id :name, use: :slugged
  has_many :videos
  ...
end

video.rb

class Video < ActiveRecord::Base
  extend FriendlyId
  friendly_id :title, use: :slugged
  belongs_to :team
  ...
end

routes.rb

...
resources :teams, :path => '', :except => [:index] do 
  resources :videos, :path => '', :except => [:index] do
    get 'full_res_download'
    get 'web_download'
  end
end
...

Thank you for your help.


回答1:


I think it will work if you use this as your url helper instead:

edit_team_video_path(@video.team, @video)

If you give it the id explicitly, that's what it will use.



来源:https://stackoverflow.com/questions/10726665/how-to-use-the-slug-from-friendly-id-in-a-nested-route

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!