我在config / routes.rb
中有这个 resources :my_objects
我有app / controllers / my_objects_controller.rb
def edit
respond_to do |format|
@my_object = MyObject.find(params[:id])
format.json {
render :json => @my_object
}
end
end
但是当我尝试使用
联系此URL(通过GET)时,我从我的JQuery获得了404http://localhost:3000/my_objects/edit/8
我也试过
http://localhost:3000/my_objects/edit?id=8
仍然得到了404.从编辑链接获取数据需要使用哪个正确的URL?
答案 0 :(得分:0)
resources
创建的RESTful路由遵循以下模式:
method path controller action
---------------------------------------------------------
GET /my_objects #index
POST /my_objects #create
GET /my_objects/new #new
GET /my_objects/:id/edit #edit
GET /my_objects/:id #show
PATCH|PUT /my_objects/:id #update
DELETE /my_objects/:id #destroy
答案 1 :(得分:0)
应该是
http://localhost:3000/my_objects/8/edit
不
http://localhost:3000/my_objects/edit/8
请参阅@max答案以获得澄清。