I have a form which has a select box with name of cities from the database. When i select a city and click continue, i want it to grab the city_id selected and redirect me to another page (:controller=> 'people', action => 'index') where i am going to make use of that city_id. How do i do that?Iam using RAILS 3.This is what i have..
View
<%= 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%>
Controller
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
People Controller
class PeopleController < ApplicationController
def index
@city = City.find(params[:city_id])
end
end
You can do this by setting a session variable in your
nextaction:You can also do this with a flash variable, but session is likely the proper place.