Ok so I have a rails app where user can create pins. Then they can comments those pins. What I what to do is to remove the controller name in pin url.
So instead of: http://localhost:3000/pins/name I have http://localhost:3000/name
**I did that by using this in my **config/routes.rb****
Rails.application.routes.draw do
resources :pins, :only => [:index, :new, :create], :path => '' do
resources :comments
member do
put 'upvote'
end
end
But now, when I try to comment a pin I have this error:
wrong constant name 'pin name'
and the error come fom this lines from my comments_controller.rb:
def load_commentable
resource, id = request.path.split('/')[1, 2]
@commentable = resource.singularize.classify.constantize.friendly.find(id)
end
Any ideas how I could fix this ?
EDIT:
**rake routes** output:
pin_comments GET /:pin_id/comments(.:format) comments#index
POST /:pin_id/comments(.:format) comments#create
new_pin_comment GET /:pin_id/comments/new(.:format) comments#new
edit_pin_comment GET /:pin_id/comments/:id/edit(.:format) comments#edit
pin_comment GET /:pin_id/comments/:id(.:format) comments#show
PATCH /:pin_id/comments/:id(.:format) comments#update
PUT /:pin_id/comments/:id(.:format) comments#update
DELETE /:pin_id/comments/:id(.:format) comments#destroy