好的,所以我有一个 Rails 应用程序,用户可以在其中创建引脚。然后他们可以评论这些别针。我要做的是删除 pin 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
但是现在,当我尝试评论 pin 时,我遇到了这个错误:
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