2013-02-07 89 views
0

我正在設置nested_form gem,如下所述:https://github.com/ryanb/nested_formnested_form gem的問題

問題是我的f.fields_for似乎回來空了。我沒有任何錯誤,但在頁面上我只看到「添加位置」鏈接,該鏈接什麼都不做。

數據模型是Events => event_locations < =地點,event_locations充當聯結對象。

這裏是在我的視圖的形式:

<%= nested_form_for @event do |f| %> 
    <%= @event.locations %> 
    <%= f.fields_for :locations do |task_form| %> 
     <%= task_form.text_field :name %> 
     <%= task_form.link_to_remove "Remove this Location" %> 
    <% end %> 

    <p><%= f.link_to_add "Add a Location", :locations %></p> 
    <% end %> 

這是我的事件控制器:

def new 
    logger.debug "*** before Event.new" 
    @event = Event.new 
    logger.debug "*** after Event.new" 
    3.times do 
     @event.locations.build 
    end 
    end 

event.rb

has_many :days_events 
    has_many :events_locations 
    has_many :locations, :through => :events_locations 

    # Validations 
    validates_presence_of :name 

    accepts_nested_attributes_for :locations 

event_location.rb

belongs_to :event 
belongs_to :location 

accepts_nested_attributes_for :location 

location.rb

has_many :events_locations 
has_many :events, :through => :events_locations 


#validations 
validates_presence_of :name 

accepts_nested_attributes_for :events 

回答