呈现另一个控制器动作和填写表格
render another controller action and filling form
当我提交表单时,如果它有一些错误,我们可以这样做:
def create
@proposal = Proposal.new(proposal_params)
if @proposal.save
redirect_to @proposal
else
render :new
end
end
但我的表单正在提交给另一个控制器操作
我怎样才能得到相同的结果来渲染其他控制器的 :new 动作,传递前一个控制器的 id 以显示表单错误并用给定的文本呈现表单。
因为如果我这样做:
def create
@proposal = Proposal.new(proposal_params)
if @proposal.save
redirect_to @proposal
else
redirect_to other_controller_path(@user)
end
end
不会显示验证错误
将@proposal.errors 传递给 flash 中的重定向:
redirect_to other_controller_path(@user), notice: @proposal.errors
或类似的东西,具体取决于您在应用中设置错误的方式。
当我提交表单时,如果它有一些错误,我们可以这样做:
def create
@proposal = Proposal.new(proposal_params)
if @proposal.save
redirect_to @proposal
else
render :new
end
end
但我的表单正在提交给另一个控制器操作
我怎样才能得到相同的结果来渲染其他控制器的 :new 动作,传递前一个控制器的 id 以显示表单错误并用给定的文本呈现表单。
因为如果我这样做:
def create
@proposal = Proposal.new(proposal_params)
if @proposal.save
redirect_to @proposal
else
redirect_to other_controller_path(@user)
end
end
不会显示验证错误
将@proposal.errors 传递给 flash 中的重定向:
redirect_to other_controller_path(@user), notice: @proposal.errors
或类似的东西,具体取决于您在应用中设置错误的方式。