Email notifications system in Rails project I'm working on the Rails project where I have many-to-many :through relationship.  Each setting has many notifications through email_notification model where the notification can be primary or a secondary.

schema.rb

create_table "email_notifications", :force =&gt; true do |t|
  t.integer "setting_id"
  t.integer "notification_id"
  t.boolean "primary"
  t.boolean "secondary"

create_table "notifications", :force =&gt; true do |t|
  t.string   "name"

create_table "settings", :force =&gt; true do |t|
  t.string   "truck_identification"
  t.string   "email_periods"
  t.integer  "email_recepient_id"
  t.datetime "created_at",                             :null =&gt; false
  t.datetime "updated_at",                             :null =&gt; false
  t.integer  "truck_fleet_id"


In models

class EmailNotification &lt; ActiveRecord::Base
  attr_accessible :notification_id, :setting_id, :primary, :secondary
  belongs_to :notification
  belongs_to :setting



class Notification &lt; ActiveRecord::Base
  attr_accessible :name

  has_many :settings, :through =&gt; :email_notifications
  has_many :email_notifications
end


class Setting &lt; ActiveRecord::Base
  # TODO: refactor this bullshit
  attr_accessible :email_periods, :email_recepient_id, :truck_identification, 
                  :truck_fleet_id

  has_many :notifications, :through =&gt; :email_notifications
  has_many :email_notifications
  validates_uniqueness_of :truck_fleet_id 
  # validates :email, :email_format =&gt; true
end


I used this many-to-many relationship because I need flexibility to add up new Notifications over the time, and keep ability to make notifications flexible as possible.  For example, I might add a column frequency, or interval etc. 

Let me know if you can find a better solution.
# TODO: refactor this bullshit


While amusing to devs, swear words probably don't belong in production code.

In your copypasta of schema.rb, I do believe you forgot to paste the end keywords. 

As a side note, you can also write null: false instead of :null =&gt; false; as far as I can tell, this is the accepted syntax. You can do the same thing with through: :email_notifications and anything of the form Symbol =&gt; BasicObject. This syntax was added after this question was posted, but if you're still interested in updating it, that's what I'd do.

Personally, I prefer to use Symbols instead of Strings as table names, though that's entirely personal preference.

In your models, you also forgot an end at the end of your first class.

Aside from that... Well, honestly, it looks good to me. Since I can't really tell what Setting and Notification are supposed to represent on a more concrete level than their names alone can give, I can't give good advice on how to link them together. However, I don't see why you need a many-to-many, if I'm understanding the purpose of Setting and Notification correctly. It seems like it could be a one-to-many relationship, though I'm not sure which side should be the one.