Ruby on rails 更新rails中的路由不';你对事后行动反应不好吗? class FrogsController
大家好。我想知道是否有人能向我解释为什么rails中的更新路由不能将我的后重定向(底部的定制方法)带回家。当我在after_操作中包含update时,我得到的错误是“缺少模板青蛙/update”。 这将导致我在update方法中手动添加重定向到frogs路径Ruby on rails 更新rails中的路由不';你对事后行动反应不好吗? class FrogsController,ruby-on-rails,ruby,routing,ruby-on-rails-4,Ruby On Rails,Ruby,Routing,Ruby On Rails 4,大家好。我想知道是否有人能向我解释为什么rails中的更新路由不能将我的后重定向(底部的定制方法)带回家。当我在after_操作中包含update时,我得到的错误是“缺少模板青蛙/update”。 这将导致我在update方法中手动添加重定向到frogs路径 谢谢 after_action回调在该操作运行后触发。不能使用它来渲染或重定向。通过调用以下方法在操作本身中执行此操作: class FrogsController < ApplicationController before_a
谢谢 after_action回调在该操作运行后触发。不能使用它来渲染或重定向。通过调用以下方法在操作本身中执行此操作:
class FrogsController < ApplicationController
before_action :find_frog, only: [:edit, :update, :show, :destroy]
after_action :redirect_home, only: [:update, :create, :destroy]
def index
@frogs = Frog.all
end
def new
@ponds = Pond.all
@frog = Frog.new
end
def create
@frog = Frog.create(frog_params)
end
def edit
@ponds = Pond.all
end
def update
@frog.update_attributes(frog_params)
end
def show
end
def destroy
@frog.destroy
end
private
def find_frog
@frog = Frog.find(params[:id])
end
def frog_params
params.require(:frog).permit(:name, :color, :pond_id)
end
def redirect_home
redirect_to frogs_path
end
end
错误
缺少模板青蛙/update
意味着您没有在更新方法中呈现此输出
def update
...
redirect_home
end