你一定記得你不是「發送」一個變量到另一個動作;你調用另一個動作,並具有可變填充它(數據):
1.實例變量
您可以設置一個實例變量,那麼這將是可用下一個動作:
def your_action
@search = "abc"
respond_to do |format|
format.html { redirect_to home_user_path } #-> @search will be available in the other view
end
end
2.會話
您目前正在嘗試使用sessions
填充數據:
def your_action
redirect_to home_user_path, search: "abc"
end
#app/views/controller/your_action.html.erb
<%= flash[:search] %>
3. URL
最後,你可以通過你的路由設置在URL中的價值:
def your_action
redirect_to home_user_path(search: "abc") #-> you'll probably need to set the user object too, judging from the route name
end
這條命LD填充一些GET
request params路線:url.com/action?param=value
這一切的託換,如前所述,是,你不發送的變量,你會在你的當前控制器動作來初始化它,然後讓下一個動作調用它。
你想發送一個URL參數嗎?如果是,則執行'redirect_to home_user_path(搜索:「abc」)'' – Santhosh