找不到控制器的操作
浏览完我的代码后,我有一个与原始问题不同的问题,而不是编写一个新问题。我将把旧的部分留在底部,并在这里发布新的问题。我这样做是因为它们密切相关。
新:
我收到一条错误消息,说
Unknown action
The action 'response' could not be found for CrawlerController
我会保持简单,但模型、控制器和路由的代码位于上一个问题的下面。
基本的总结是响应是 CrawlerController 中的一个定义,就像 add_Request 一样。 路由是这样匹配的:
match "/requests/new" => "crawler#add_Request"
match 'requests/:id' => 'crawler#response'
这是根据用户请求的控制器代码:
class CrawlerController < ApplicationController
def add_Request
@request = Request.new(params[:request])
respond_to do |format|
if @request.save
format.html { redirect_to(@request, :notice => 'Request was successfully created.') }
format.xml { render :xml => @request, :status => :created, :location => @request }
else
format.html { render :action => "new" }
format.xml { render :xml => @request.errors, :status => :unprocessable_entity }
end
end
end
def response
@request = Request.find(params[:id])
respond_to do |format|
format.html
format.js { render :json => @request }
end
end
def show
@request = Request.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @request }
format.json{
render :json => @request.to_json
}
end
end
end
Having gone through my code I have a separate problem from my original question and rather than writing a new question. I will leave the old part at the bottom of this and post the new problem here. I do this because they are closely related.
New:
Im getting an error message saying
Unknown action
The action 'response' could not be found for CrawlerController
I'll keep it simple but the code for model, controller and routes are below in the previous question.
A basic run down is response is a def within CrawlerController as is add_Request.
The routes are matched as such:
match "/requests/new" => "crawler#add_Request"
match 'requests/:id' => 'crawler#response'
Here is controller code as per user request:
class CrawlerController < ApplicationController
def add_Request
@request = Request.new(params[:request])
respond_to do |format|
if @request.save
format.html { redirect_to(@request, :notice => 'Request was successfully created.') }
format.xml { render :xml => @request, :status => :created, :location => @request }
else
format.html { render :action => "new" }
format.xml { render :xml => @request.errors, :status => :unprocessable_entity }
end
end
end
def response
@request = Request.find(params[:id])
respond_to do |format|
format.html
format.js { render :json => @request }
end
end
def show
@request = Request.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.xml { render :xml => @request }
format.json{
render :json => @request.to_json
}
end
end
end
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
请重新检查控制器的代码,因为我可以看到它,
因此缺少一端,并且您的
response
操作是在add_Request
中定义的please recheck code of controller as I can see it
so one end is missing an your
response
action is defined insideadd_Request