0
我有一个控制器:重定向回来的错误
控制器/ streets_controller.rb
class StreetsController < ApplicationController
before_action :set_street, only: [:show, :edit, :update, :destroy]
def show
@house = @street.houses.build
end
.......
而对于show
作用的图。在那里,我也表现形式,创造新街的房屋:
的意见/街道/ show.html.erb
<h1>Street</h1>
<p>@street.name</p>
<%= render '/houses/form', house: @house %>
当有人提交houses/form
请求转到houses_controller.rb
class HousesController < ApplicationController
def create
@house = House.new(house_params)
respond_to do |format|
if @house.save
format.html { redirect_back(fallback_location: streets_path) }
format.json { render :show, status: :created, location: @house }
else
format.html { redirect_back(fallback_location: streets_path) }
format.json { render json: @house.errors, status: :unprocessable_entity }
end
end
end
到目前为止,它的工作原理是,当有人插入正确house_params
它重定向回,并创建房子正确
但是,当有人插入错误house_params
它redirects_back但它并不显示在表格中房子的错误,它显示了新房子@house = @street.houses.build
我怎样才能重定向到StreetsController
与@house
形式对象,以便显示错误并填充房屋形式?
谢谢
用户可能重定向到的可能页面是什么? –