1
我有一個表格,其中有一個從數據庫中選擇了城市名稱的框。當我選擇一個城市並點擊繼續時,我希望它抓取所選的city_id
,並將我重定向到另一頁(:controller=> 'people', action => 'index')
,我將在那裏使用該city_id
。我該怎麼做呢?蔭使用Rails 3,本就是我..如何從選擇框中訪問ID?
查看
<%= form_for :cities, :url=>{:action =>"next"} do |f| %>
<%= collection_select(nil, :city_id, City.all, :id, :name ,:prompt=>"Select your city") %>
<%=f.submit "continue" %>
<%end%>
控制器
class HomeController < ApplicationController
def next
@city = City.find(params[:city_id])
redirect_to :controller => "people", :action => "index"
end
def new
@city = City.new
end
end
人民控制器
class PeopleController < ApplicationController
def index
@city = City.find(params[:city_id])
end
end
非常感謝您! – katie