Can't seem to get my HABTM form to work

What I’m trying to do seems easy, but I’ve been trying to get it right
for 3 days now, and am at my wits end.

What I have:
2 tables + 1 join table.
Subscribers, Cities, and Cities_Subscribers

Form looks like this:
TEXTBOX - EMAIL
CHECKBOXES - CITIES
SUBMIT

My models are like so:

class Subscriber < ActiveRecord::Base
attr_accessor :email, :subscriber_id, :city_id
has_and_belongs_to_many :cities
accepts_nested_attributes_for :cities
end

class City < ActiveRecord::Base
has_and_belongs_to_many :subcribers
end

my controller:
def create
@subscriber = Subscriber.new(params[:subscriber])
if @subscriber.save
flash[:notice] = ‘Album was successfully created.’
redirect_to(:action => ‘index’)
else
flash[:notice] = ‘[email protected]!!.’
redirect_to(:action => ‘test123’)
end
end

My Form:

<%= semantic_form_for Subscriber.new do |f| %>
<%= f.inputs :email %>

<%= f.semantic_fields_for Subscriber.new do |g| %>
<% @cities.each do |ct| %>
<%= ct.name %>
<%= check_box_tag “subscriber[city_ids][]”, ct.id %>

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


Submitting the form is giving me the following error right now:
Mysql::Error: Column ‘email’ cannot be null: INSERT INTO subscribers
(created_at, email, updated_at) VALUES (‘2010-10-18 11:17:32’,
NULL, ‘2010-10-18 11:17:32’)


but my params on same error page looks like this:
{“commit”=>“Create Subscriber”,
“subscriber”=>{“city_ids”=>[“1”,
“132”,
“131”,
“144”,
“199”],
“email”=>“[email protected]”},
“authenticity_token”=>“JvO4pkQPabVJgJsZxJiqeawD3m/SGCw5UPExqtZnLAs=”,
“utf8”=>“✓”}

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs