Rails自动添加的路径是什么?假设你有一个问题资源,你会自动获得questions_path,question_path等。我在哪里可以看到他们的解决方案和我得到的结果?动态路径助手栏杆
Q
动态路径助手栏杆
18
A
回答
34
如果你想创建show
行动帮助这部分可能会有所帮助http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use
Verb Path Action Helper
GET /photos index photos_path
GET /photos/new new new_photo_path
POST /photos create photos_path
GET /photos/:id show photo_path(:id)
GET /photos/:id/edit edit edit_photo_path(:id)
PUT /photos/:id update photo_path(:id)
DELETE /photos/:id destroy photo_path(:id)
你可以写
photo_path(@photo.id)
其中@photo
是你的模型对象。或者,如果它响应id
方法,则可以直接通过@photo
。
photo_path(@photo)
edit_photo_path(@photo)
您也可以加载rails console
(端),以及使用app
像测试路由,以便app.photo_path(1)
(它会告诉你用id
照片的路线等于1
)
8
只需使用:
rake routes
这将列出定义的所有路线。第一列与你的路径助手相关。
0
如果您在在下面的routes文件:
resources :questions
然后Rails提供以下宁静的路线你:
GET /questions index list of questions
GET /questions/new new show new question form
POST /questions create create a new question
GET /questions/:id show show a specific question
GET /questions/:id/edit edit show form to edit question
PUT /questions/:id update update a specific question
DELETE /questions/:id destroy delete a specific question
您还可以运行rake:routes来查看正在生成的内容。
相关问题
- 1. 栏杆助手在栏杆中
- 2. Zend Framework助手的路径
- 3. 自动完成一个动态栏杆
- 4. 帮助程序中的动态路径
- 5. 做耙路时丢失助手路径
- 6. 在把手中的动态路径
- 7. 动态根路径路径
- 8. Rails的路径助手不重写URL在地址栏
- 9. Rails路径助手不一致
- 10. 修改路径的URL助手?
- 11. RoR的路径助手链接向后
- 12. 基本路径视图助手
- 13. Zend Framework助手路径问题
- 14. 循环中的路径助手
- 15. Rails - 在哪里放置路径助手?
- 16. Rails助手找到当前路径
- 17. Rails 4.0中的路径,路径助手和STI
- 18. 在Rails 3路径中重命名路径助手
- 19. 需要一只手用栏杆加入
- 20. CreateDirRequest - 手动更改路径
- 21. 动态FileField路径
- 22. 动态获取路径路径
- 23. Rails - 带参数的成员动作 - 路径助手?
- 24. 把手内环路助手
- 25. 栏杆路由:组合索引并显示动作
- 26. 导轨 - 命名空间的路由路径的助手
- 27. Restful路线助手使用'。'而不是路径中的'/'
- 28. Rails路由:为路径助手提供默认值
- 29. 指定在调用视图助手时使用的助手路径
- 30. multer:动态目标路径
[here](http://guides.rubyonrails.org/routing.html#seeing-existing-routes-with-rake)是什么'rake routes'给你的详细解释 – 2012-08-08 11:27:12
我看不到这是怎么回事显示我可以作为参数传递给帮手等? – LuckyLuke 2012-08-08 12:22:57
@Dude,看我的更新 – evfwcqcg 2012-08-08 13:46:08