Luc*_*uke 23 ruby ruby-on-rails ruby-on-rails-3
Rails自动添加的路径是什么?假设您有一个问题资源,您自动获得questions_path,question_path等.我在哪里可以看到他们解决了什么以及我得到了什么?
evf*_*qcg 41
本节可能会有所帮助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)
Run Code Online (Sandbox Code Playgroud)
如果你想创建一个帮助show
你的行动,你可以写
photo_path(@photo.id)
Run Code Online (Sandbox Code Playgroud)
@photo
你的模型对象在哪里.或者,@photo
如果它响应id
方法,您可以直接传递.
photo_path(@photo)
edit_photo_path(@photo)
Run Code Online (Sandbox Code Playgroud)
您也可以rails console
使用app
类似的方式加载(在终端中)和测试路线app.photo_path(1)
(它将显示id
相等的照片路线1
)