我有一个包含User和Project模型的应用程序。我在这两个模型之间有以下关系:
USER
has_many :authorships , :foreign_key => :author_id
has_many :moderatorships, :foreign_key => :moderator_id
has_many :authored_projects, :through => :authorships, :class_name => 'Project'
has_many :moderated_projects, :through => :moderatorships, :class_name => 'Project'
我想要一个/ users / id / favorite_projects和/ users / id / moderated_projects的路由。我的routes.rb
中有以下内容map.resources :users,:has_many => [:authored_projects, :moderatored_projects], :shallow => true, :collection => {:logins => :get}
但是当我运行rake路线时,我得到了
user_authored_projects GET /users/:user_id/authored_projects(.:format) {:controller=>"authored_projects", :action=>"index"}
但是,我真的没有authored_projects控制器。我怎样才能做到这一点?
答案 0 :(得分:0)
我想你想在你的路线中这样做:
map.resources :users do |users|
users.resources :authored_projects, :controller => :projects
users.resources :moderated_projects, :controller => :projects
end
但我认为你想做别的事情,比如:
map.resources :users, :member => [:authored_projects, :moderated_projects]
然后在authored_projects
中创建操作moderated_projects
和UsersController
。