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
形式對象,以便顯示錯誤並填充房屋形式?
謝謝
用戶可能重定向到的可能頁面是什麼? –