[英]How to make an url dynamically in rails on form submit
我在rails中有一個表單:
<form class="clearfix" method="GET" action="<%= url_for hotels_path %>">
<input type="text" name="country" />
<input type="text" name="city" />
</form>
我想提交重定向到url:
/hotels/:country/:city
國家和城市是我的領域的價值所在。
在不使用JavaScript的情況下,我該如何管理?
謝謝
您可以在服務器端進行重定向,例如這樣(未經測試):
class HotelsController < ActionController::Base
def index
redirect_to hotels_path + "/#{params[:country]/#{params[:city]}"
end
end
您無法使用javascript來管理此問題,因為您在解析erb模板時只設置了一次action
,並且當您要根據用戶操作對其進行更改時,您必須使用javascript。 而已!
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.