2013-01-04 54 views
-1

我似乎無法嵌套窗體工作,我或者看不到它或不明白它。這裏的錯誤嵌套窗體軌跡質量分配問題

Can't mass-assign protected attributes: location 

現在在這裏,我怎麼寫我

型號/事件:

#Data 
    attr_accessible :customer_id, :description, :location_attributes 
#Relationship 
    has_many :locations 
    accepts_nested_attributes_for :locations, :allow_destroy => true 

型號/地點:

#Data 
    attr_accessible :address, :customer_id, :event_id, :latitude, :longitude 
#Relationship 
    belongs_to :customer 
    belongs_to :event 

控制器:

def create 
    @event = current_customer.events.build(params[:event]) 
    ... 

查看:

<%= f.fields_for :location do |e| %> 
    <%= e.hidden_field :longitude %> 
    <%= e.hidden_field :latitude %> 
    <% end %> 

PARAMS

"location"=>{"longitude"=>"-80.9449995", 
"latitude"=>"46.435371599999996"}, 

我在軌道3.2.9和VPS服務器託管。現在我不明白爲什麼它不工作。

回答

1

你的形式應該是,並注意多:

<% f.fields_for :locations do |location_form| %> 

這是因爲你在渲染其與表單對象相關聯的位置對象的字段。這將自動爲這些字段命名爲location_attributes的參數,以便它們隨後傳遞到您的控制器,然後您的模型將接受它們。

+0

謝謝你解決問題,但現在由於某些原因,地點不會被創建 – Jseb