【发布时间】:2015-03-04 07:28:37
【问题描述】:
好的,我有一个 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'
错误来自我的 cmets_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
【问题讨论】:
-
能否提供
wrong constant name 'pin name'错误的所有回溯? -
+
rake routes命令的输出 -
您需要为此添加自定义路由,但请注意限制有效的引脚名称,否则您将与其他路由发生冲突。
标签: ruby-on-rails ruby pins