I am using the act_as_votable gem to be able to like objects from two different models.
Everything works as expected in the Rails Console.
I am having trouble being able to create the route that I need in controller whose resources are being nested.
The route file currently looks like this.
KitsIo::Application.routes.draw do
resources :kits do
get :like, :on => :member
resources :things, shallow: true
get :like, :on => :member
end
root 'kits#index'
end
Running rake routes:
like_kit_path GET /kits/:id/like(.:format) kits#like
kit_things_path GET /kits/:kit_id/things(.:format) things#index
POST /kits/:kit_id/things(.:format) things#create
new_kit_thing_path GET /kits/:kit_id/things/new(.:format) things#new
edit_thing_path GET /things/:id/edit(.:format) things#edit
thing_path GET /things/:id(.:format) things#show
PATCH /things/:id(.:format) things#update
PUT /things/:id(.:format) things#update
DELETE /things/:id(.:format) things#destroy
GET /kits/:id/like(.:format) kits#like
kits_path GET /kits(.:format) kits#index
POST /kits(.:format) kits#create
new_kit_path GET /kits/new(.:format) kits#new
edit_kit_path GET /kits/:id/edit(.:format) kits#edit
kit_path GET /kits/:id(.:format) kits#show
PATCH /kits/:id(.:format) kits#update
PUT /kits/:id(.:format) kits#update
DELETE /kits/:id(.:format) kits#destroy
root_path GET / kits#index
The route to the like_kit_path is created correctly and I am able to like a kit from the Kits controller.
The problem I am trying to solve is being able to create a like_things_path that will route to the things controller.
like_things_path GET /things/:id/like(.:format) things#like
If I change the route file to this:
KitsIo::Application.routes.draw do
resources :kits do
get :like, :on => :member
resources :things do
get :like, :on => :member
end
end
root 'kits#index'
end
Then the route is created correctly to the things controller.
like_kit_path GET /kits/:id/like(.:format) kits#like
like_kit_thing_path GET /kits/:kit_id/things/:id/like(.:format) things#like
kit_things_path GET /kits/:kit_id/things(.:format) things#index
POST /kits/:kit_id/things(.:format) things#create
new_kit_thing_path GET /kits/:kit_id/things/new(.:format) things#new
edit_kit_thing_path GET /kits/:kit_id/things/:id/edit(.:format) things#edit
kit_thing_path GET /kits/:kit_id/things/:id(.:format) things#show
PATCH /kits/:kit_id/things/:id(.:format) things#update
PUT /kits/:kit_id/things/:id(.:format) things#update
DELETE /kits/:kit_id/things/:id(.:format) things#destroy
kits_path GET /kits(.:format) kits#index
POST /kits(.:format) kits#create
new_kit_path GET /kits/new(.:format) kits#new
edit_kit_path GET /kits/:id/edit(.:format) kits#edit
kit_path GET /kits/:id(.:format) kits#show
PATCH /kits/:id(.:format) kits#update
PUT /kits/:id(.:format) kits#update
DELETE /kits/:id(.:format) kits#destroy
root_path GET / kits#index
Is there another way to create a custom route to the things controller other than in the second example of the route file?
While this creates the correct route, it breaks much of the code that is currently working.
Thanks in advance for any assistance you can provide in helping me solve this issue will be greatly appreciated.