我目前有一个路径文件
devise_for :users, controllers: {omniauth_callbacks: "omniauth_callbacks"}
resources :users do
resources :posts
end
match "posts" => "posts#main"
get "home/index"
root :to => 'home#index'
end
我现在想做的是,/users/:user_id/problems/:id
显示为/problems/:id
。但不确定我应该如何将它放入路线?
注意:我确实在用户和帖子之间建立了关系。
class User < ActiveRecord::Base
has_many :posts
和
class Post < ActiveRecord::Base
belongs_to :user
由于
UDPATE:我得到的错误是Couldn't find User without an ID
答案 0 :(得分:0)
您需要以下列方式使用浅路线,
resources :users, :shallow => true do |user|
user.resources :posts
end