views:

25

answers:

0

Why can't I add new items to my database using a has_many :through relationship? I am missing something, the form shows up right, but I just can't add anything to my database. I hit enter and nothing happens.

I'm running mysql / rails3 / using formtastic.

Subscriber.rb (Subscriber model)

class Subscriber < ActiveRecord::Base
attr_accessor :email, :city_ids
has_many :email_lists
has_many :cities, :through => :email_lists
validates_presence_of :email
end

City.rb (City model)

class City < ActiveRecord::Base
has_many :email_lists
has_many :subscribers, :through => :email_lists
has_many :deals
#has_slug :slug
acts_as_mappable :default_units => :miles,
                 :lat_column_name => :lat,
                 :lng_column_name => :lng

end

Email_list.rb(Email List model)

class EmailList < ActiveRecord::Base
  belongs_to :subscriber
  belongs_to :city

  validates_presence_of :subscriber_id
  validates_presence_of :city_id
end

Subscribers_controller:

 def index

    @cities = City.find(:all, :order => 'state, name')
    @zip = params[:zipcode]
    @ziploc = GeoKit::Geocoders::MultiGeocoder.geocode('45408')
    @nearest = City.find(:all,
             :origin => [@ziploc.lat, @ziploc.lng],
             :order => 'distance',
             :limit => '10')
    @subscriber = Subscriber.new(params[:subscriber])
   end

My view(using formtastic):

<%= semantic_form_for @subscriber do |f| %>
      <%= f.inputs do %>
        <%= f.input :email %>

        <%=  f.input :cities, :as => :check_boxes, :collection => @nearest %>


      <% end %>
      <%= f.buttons %>
   <% end %>