0

我有一个 Rails 应用程序,Users可以在其中创建Programs和其他尚未到来的东西,我们会说Plans(假设地)。

Users还可以like ProgramsPlans。(就像是多态的)

我试图找出路线,以便我可以看到ProgramsaUser创建的所有东西 a User likes,或者只是Programs或只是Plansa User likes。我有这些路线,但这似乎不对。

resources :users, :only => [:index,:show] do
    resources :programs, :only => [:index]
    resources :likes, :only => [:index] do
        resources :programs, :only => [:index]
    end
end

该路由需要programs一个user likesURL,例如:users/user_id/likes/like_id/program。

如何创建一个 URL,例如:users/user_id/likes/programs 并获取所有喜欢的程序。

I am using the Socialization Gem which has a method for "likeables_relation(Class)" which returns a relation of whatever class is requested. I just need help with the routing.

4

1 回答 1

1

I've just tried with the following routes:

resources :users, :only => [:index,:show] do
  resources :programs, :only => [:index]
  resources :likes, :only => [:index] do
    collection do
      get :programs
    end
  end
end

and the

http://localhost:3000/users/1/likes/programs 

works fine.

It required adding a new action 'programs' to the LikesController class.

This is what rake routes returns:

programs_user_likes GET /users/:user_id/likes/programs(.:format) likes#programs
于 2013-03-30T16:57:20.713 回答