好吧,我有一个rails应用程序,用户可以在其中创建引脚。然后他们可以评论这些引脚。我该做什么是删除引脚url中的控制器名称。从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此行FOM来的错误:
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
您能否提供'错误的常数名称'pin name''错误的所有回溯? – 2015-03-02 23:20:04
+“rake routes”命令的输出 – 2015-03-02 23:20:35
您需要为此添加自定义路由,但要小心限制一个有效的引脚名称,否则将与其他路由发生冲突。 – tadman 2015-03-02 23:21:56