ユーザーがピンを作成できるレールアプリがあります。次に、それらのピンにコメントを付けることができます。私がすべきことは、ピン URL のコントローラー名を削除することです。
代わりに: http://localhost:3000/pins/name私はhttp://localhost:3000/ name を持っています
**config/routes.rb****でこれを使用してそれを行いました****
Rails.application.routes.draw do
resources :pins, :only => [:index, :new, :create], :path => '' do
resources :comments
member do
put 'upvote'
end
end
しかし今、ピンにコメントしようとすると、次のエラーが発生します。
wrong constant name 'pin name'
エラーは、comments_controller.rb の次の行から発生します。
def load_commentable
resource, id = request.path.split('/')[1, 2]
@commentable = resource.singularize.classify.constantize.friendly.find(id)
end
これを修正する方法はありますか?
編集:
**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