你可能有這樣的在你的路線 -
resources :posts do
resources :users
end
耙路線會產生下面的映射 -
post_users GET /posts/:post_id/users(.:format) {:action=>"index", :controller=>"users"}
POST /posts/:post_id/users(.:format) {:action=>"create", :controller=>"users"}
new_post_user GET /posts/:post_id/users/new(.:format) {:action=>"new", :controller=>"users"}
edit_post_user GET /posts/:post_id/users/:id/edit(.:format) {:action=>"edit", :controller=>"users"}
post_user GET /posts/:post_id/users/:id(.:format) {:action=>"show", :controller=>"users"}
PUT /posts/:post_id/users/:id(.:format) {:action=>"update", :controller=>"users"}
DELETE /posts/:post_id/users/:id(.:format) {:action=>"destroy", :controller=>"users"}
posts GET /posts(.:format) {:action=>"index", :controller=>"posts"}
POST /posts(.:format) {:action=>"create", :controller=>"posts"}
new_post GET /posts/new(.:format) {:action=>"new", :controller=>"posts"}
edit_post GET /posts/:id/edit(.:format) {:action=>"edit", :controller=>"posts"}
post GET /posts/:id(.:format) {:action=>"show", :controller=>"posts"}
PUT /posts/:id(.:format) {:action=>"update", :controller=>"posts"}
DELETE /posts/:id(.:format) {:action=>"destroy", :controller=>"posts"}
以上解釋您可以使用的網址以及需要傳遞的對象。
對於帖子的用戶連接 -
<%= link_to "Post User details", post_user_path(post, post.user) %>
OR
<%= link_to "Post User details", url_for([post, post.user]) %>
Jayendra帕蒂爾<3 –
你可能要接受的答案,如果解決方案適用於你。會幫助人們進一步幫助你。 – Jayendra