2016-04-15 26 views
0

通過下拉菜單更新不起作用。我有一個form_tag裏面的窗體標籤我有循環。所以,該值將傳入一個數組中。我怎樣才能更新它的價值。使用下拉菜單進行更新陣列軌道

在我的週期控制器我有

def period 
@period = Period.all 
end 

def period_update 
Period.update(perio_params) 
end 

private 
def perio_params 
    params.require([:period][:subject_id]).permit(:subject_id) 
end 

在period_update意見我有

<%= form_tag perio_update_institutes_path, method: :put do %> 
<% @period.each do |p|%> 
    <%= p.subject.name %> 
<%= select_tag('subject_id', options_for_select(Subject.all.collect{ |s| [s.name, s.id]}), {prompt: 'Select Sub'})%> 

<%end%> 
<%= submit_tag %> 

{"utf8"=>"✓", "_method"=>"put", "authenticity_token"=>"6LJrh2ct7VMGU6Siq/RXIMGz4kkxkVN81Jqa+eRcKb3rXq3XzBlv8gjHvjjVsPsJ4LF7ZEHF/GQ8+0906lhyUg==", "period"=>{"subject_id"=>["2", "2"]}, "commit"=>"Save changes"}

我怎麼可以更新subject_id陣列。

錯誤是

no implicit conversion of Symbol into Integer 

我有對象模型,所有的主題將是收藏。 期間模型有subject_id。我如何更新。 我是新來的鐵軌,我堅持這一點。感謝您的提前。

+0

爲什麼你有評論說部分的代碼? – Pavan

+0

哦,對不起,我嘗試了不同的語法,當我粘貼在這裏時,我沒有注意到,我已經嘗試過如下語法:'%= collection_select(s,s.id,Subject.all,:id,:name ,selected:s.id,prompt:true)%>' – Vikram

+0

你在標識符和方法調用之間有一個空格:'@period .each'。這會導致錯誤。您應該最有可能使用'collection_select('some_key','subject_id',Subject.all,:id,:name,selected:s.id,prompt:true)'。但是如果不知道更多關於控制器的信息,就不可能知道你實際上想要做什麼,因爲這非常有意義。 – max

回答

0

嘗試,如果它與options_from_collection_for_select表現不同:

<%= select_tag('subject_id', options_from_collection_for_select(Subject.all, :id, :name), {prompt: 'Select Sub'}) %>