0

I've got 2 models; Groups and Users. They're related via has_and_belongs_to_many.

This works perfectly fine so far; However: I'd like to add a user_confirmed to the story. One user adds another user; Therefore the user isn't confirmed yet. That added user can confirm himself later on, setting user_confirmed to '1' for example.

Now; I'm quite sure this is the best approach. I'm not sure on how to create this approach though. Where do I add the user_confirmed column? How do I approach and change it in my application?

Here's the related part of my schema.rb:

  create_table "groups_users", id: false, force: true do |t|
    t.integer "group_id"
    t.integer "user_id"
  end

  add_index "groups_users", ["group_id"], name: "index_groups_users_on_group_id"
  add_index "groups_users", ["user_id"], name: "index_groups_users_on_user_id"

  create_table "groups", force: true do |t|
    t.string   "name"
    t.integer  "clocktype"
    t.string   "background"
    t.datetime "created_at"
    t.datetime "updated_at"
  end


  create_table "users", force: true do |t|
    t.string   "first_name"
    t.string   "last_name"
    t.string   "password"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "email",                  default: "", null: false
    t.string   "encrypted_password",     default: "", null: false
    t.string   "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.integer  "sign_in_count",          default: 0
    t.datetime "current_sign_in_at"
    t.datetime "last_sign_in_at"
    t.string   "current_sign_in_ip"
    t.string   "last_sign_in_ip"
    t.string   "avatar_file_name"
    t.string   "avatar_content_type"
    t.integer  "avatar_file_size"
    t.datetime "avatar_updated_at"
  end

Please keep in mind that I don't want to confirm the user registration but the relation between user and group

CaptainCarl
  • 3,411
  • 6
  • 38
  • 71

1 Answers1

1

You have to change the groups_users table. This is the model that handles the relations between Users and Groups, so if you want to be able to confirm the link between a user and a group you really should alter this table.

Add a confirmed:boolean field to groups_users and then handle this value via your models to achieve the expected behavior.

Eg. each user will have a user.groups_users array with all his/her grouping relations. Each one of these will express the confirmed status and can be changed accordingly to his/her needs.

marzapower
  • 5,531
  • 7
  • 38
  • 76