gpt4 book ai didi

ruby-on-rails - 找不到 Controller 的操作

转载 作者:行者123 更新时间:2023-12-04 06:26:48 25 4
gpt4 key购买 nike

通过我的代码,我有一个与原始问题不同的问题,而不是写一个新问题。我将把旧部分留在本文底部,并在此处发布新问题。我这样做是因为它们密切相关。

新的:

我收到一条错误消息说

Unknown action

The action 'response' could not be found for CrawlerController

我会保持简单,但模型、 Controller 和路由的代码在上一个问题的下方。

一个基本的失败是响应是 CrawlerController 中的一个定义,就像 add_Request 一样。
路由匹配如下:
  match  "/requests/new" => "crawler#add_Request"
match 'requests/:id' => 'crawler#response'

这是根据用户请求的 Controller 代码:
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

最佳答案

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

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

关于ruby-on-rails - 找不到 Controller 的操作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6624968/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com