【问题标题】:How to use the slug from Friendly_id in a nested route?如何在嵌套路由中使用 Friendly_id 中的 slug?
【发布时间】:2012-05-30 09:33:19
【问题描述】:

在编辑和创建时,我很难在嵌套路由中制作来自 Friendly_id 的 slug?这些路线看起来很适合展示。

http://0.0.0.0:3000/test/tester2

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

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:0.0.0.0:3000/2/tester2/edit。是这样的吗:edit_tester_tester2_url(@tester,@tester2)
  • @Adam edit_team_video_path(@video.team_id, @video)

标签: ruby-on-rails ruby-on-rails-3 nested-routes friendly-id


【解决方案1】:

我认为如果你使用它作为你的 url helper 它将起作用:

edit_team_video_path(@video.team, @video)

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-12-03
    • 1970-01-01
    • 2021-11-14
    • 1970-01-01
    • 2020-01-04
    • 1970-01-01
    相关资源
    最近更新 更多