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] = 'err...@!!.'
     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| %>
      <label><%= ct.name %>
      <%= check_box_tag "subscriber[city_ids][]", ct.id %>
    </label>


<% 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"=>"elkffefe...@test.com"},
 "authenticity_token"=>"JvO4pkQPabVJgJsZxJiqeawD3m/SGCw5UPExqtZnLAs=",
 "utf8"=>"✓"}

-----------------
I'm confused where to go from here. Could really use some help asap!
thanks!

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-t...@googlegroups.com.
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en.

Reply via email to