0

我目前有一个路线文件

  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

4

1 回答 1

0

您需要按以下方式使用浅层路线,

 resources :users, :shallow => true do |user|
  user.resources :posts
 end
于 2013-03-14T07:30:30.920 回答