如何在嵌套路由中使用来自 Friendly_id 的 slug? [英] How to use the slug from Friendly_id in a nested route?

查看:41
本文介绍了如何在嵌套路由中使用来自 Friendly_id 的 slug?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在编辑和创建时,我很难在嵌套路由中从 Friendly_id 制作 slug?路线看起来很棒.

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

这是我尝试编辑 tester2 时得到的 URL:

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

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

我想看到的是:

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

这是我的代码.

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
...

感谢您的帮助.

推荐答案

我认为如果你使用它作为你的 url 助手,它会起作用:

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

edit_team_video_path(@video.team, @video)

如果你明确地给它 id,它就会使用它.

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

这篇关于如何在嵌套路由中使用来自 Friendly_id 的 slug?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆