找不到控制器的操作

发布于 2024-11-19 08:35:50 字数 1389 浏览 1 评论 0原文

浏览完我的代码后,我有一个与原始问题不同的问题,而不是编写一个新问题。我将把旧的部分留在底部,并在这里发布新的问题。我这样做是因为它们密切相关。

新:

我收到一条错误消息,说

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

一枫情书 2024-11-26 08:35:50

请重新检查控制器的代码,因为我可以看到它,

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

    def response
      @request = Request.find(params[:id])
      respond_to do |format|
        format.json {render :@request.to_json}
    end
  end

因此缺少一端,并且您的 response 操作是在 add_Request 中定义的

please recheck code of controller as I can see it

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

    def response
      @request = Request.find(params[:id])
      respond_to do |format|
        format.json {render :@request.to_json}
    end
  end

so one end is missing an your response action is defined inside add_Request

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文