views:

22

answers:

0

Hello, i have these two models:

class Artist < ActiveRecord::Base
  has_and_belongs_to_many :events
  accepts_nested_attributes_for :events
end

class Event < ActiveRecord::Base
  has_and_belongs_to_many :artists
end

And i'm trying to build a form for adding artists followed by their events, but i'm failing at that.

Here's my view code:

- form_for @artist do |f|
  %p= f.error_messages

  %p
    = f.label :name, "Name"
    = f.text_field :name
  %p
    - f.fields_for @artist.events do |f2|
      = f2.label :name, "Name"
      = f2.text_field :name

  %p= f.submit 'Create'

It creates a textbox with value="Event". What i want is one or more textboxes for adding events.