我正在尝试根据区域设置重定向。
在我的控制器上我有:
def create
@inquiry = Inquiry.new(params[:inquiry])
if @inquiry.save
redirect_to '/inquiries/thank-you'
else
render :action => 'new'
end
end
如果用户填写fr/contact-us
我想redirect_to '/inquiries/merci'
如果它填满/contact-us
我想重定向到'/inquiries/thank-you'
我试过了:
if params[:inquiry][:locale] == 'fr'
redirect_to '/fr/...'
else
redirect_to '/inquiries/thank-you'
我的参数看起来像:
{"utf8"=>"✓",
"authenticity_token"=>"s+NlJV4QqI0UOvQNTXGc8nYFr+Ib6ZpkSvd72eKbTio=",
"inquiry"=>{"name"=>"Beverly",
"email"=>"bhills_0087@veryrealemail.com",
"frame"=>"Zcaaa",
"serial_number"=>"Lkllj",
"subject"=>"Awgqd",
"message"=>"Ydsgpz lorem ipsum dolor sit amet,
consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."},
"button"=>"",
"locale"=>:fr}
答案 0 :(得分:1)
尝试使用params[:locale]
代替params[:inquiry][:locale]
:
if params[:locale].to_s == 'fr'
此外,我相信您最好使用以下内容更新routes.rb
resources :inquiry do
collection do
get :thank_you
end
end
并使用redirect_to thank_you_inquiry_path
代替视图/控制器中的硬编码网址。