Path helpers generate paths with dots instead of slashes

只谈情不闲聊 提交于 2019-12-27 13:35:48

问题


In my routes.rb I have the following:

resources :message_threads

When I call:

message_threads_path(1)

I get:

/message_threads.1

Why is this? My other resources work fine. Am I not pluralizing this correctly or something?


回答1:


Yes, this is a pluralization error.

By passing the ID 1, I assume that you wish to display a single record.

So you need to use the singular 'message_thread':

message_thread_path(1)

Which will yield:

http://localhost:3000/message_threads/1



回答2:


Sometimes this also is when you don't provide an :as parameter in your route:

delete "delete/:id" => "home#delete"

Changed to:

delete "delete/:id" => "home#delete", as: :delete

(ignore the odd example, just happened to be something we just ran into for an internal app we're building)



来源:https://stackoverflow.com/questions/5674116/path-helpers-generate-paths-with-dots-instead-of-slashes

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!