尽管在 config/routes.rb 中定义了 "resources",但仍获得 404
Getting 404 despite having defined "resources" in config/routes.rb
我的 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 收到了 404
http://localhost:3000/my_objects/edit/8
我也试过了
http://localhost:3000/my_objects/edit?id=8
仍然得到 404。什么是正确的 URL 我需要使用它来从我的编辑中获取数据 link?
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
应该是
http://localhost:3000/my_objects/8/edit
没有
http://localhost:3000/my_objects/edit/8
请参阅@max 回答以获取说明。
我的 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 我需要使用它来从我的编辑中获取数据 link?
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
应该是
http://localhost:3000/my_objects/8/edit
没有
http://localhost:3000/my_objects/edit/8
请参阅@max 回答以获取说明。