我可以看到裏面的參數中的ID在日誌中,但我不能訪問它在controller.Can任何機構,請告訴我怎麼回事,我可以做什麼?顯然 @city=City.find(params[:cities][:city_id])
沒有做job.Thank你我如何從一個collection_select表單中獲取一個id?
<%= form_for :city, :url=>{:action =>"next"} do |f| %>
<%= f.collection_select(:city_id, City.all, :id, :name ,:prompt=>"Select your city") %>
<%=f.submit "continue" %>
<%end%>
首頁控制器
def next
@city=City.find(params[:city_id])
session[:city_id] = @city.id
redirect_to :controller=>"parks",:action =>"show"
end
在日誌
Started POST "/home/next" for 127.0.0.1 at 2011-10-21 12:16:37 -0700
Processing by ParkController#show as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"7VVJ9GHcU4miYLCkSt91S674GGTScor86Tcsz7O25ik=", "city_id"=>"2", "commit"=>"continue"}
Rendered park/show.html.erb within layouts/header (2.5ms)
Completed 500 Internal Server Error in 7ms
我只是改變像上面顯示,但仍然沒有工作 – katie
好吧,那麼請發佈一個新版本的params了。 – davidb
你完全確定你的數據庫中有一個id = 2的城市嗎? –