У пользователя много профилей, таких как admin и купец и т. Д. В моей схеме rails db. Теперь как написать код, чтобы проверить, является ли текущий пользователь администратором? Дополнительная информация: Таблица пользователя отдельная, а таблица профилей - отдельно. Они связаны в модели пользователя через has_and_belongs_to_many: профилиКак проверить, является ли мой пользователь администратором в рельсах?
Вот моя схема:
create_table "profiles", force: true do |t|
t.string "name", null: false
t.string "description"
t.datetime "created_at"
t.datetime "updated_at"
end
add_index "profiles", ["name"], name: "index_profiles_on_name", unique: true, using: :btree
create_table "profiles_roles", id: false, force: true do |t|
t.integer "profile_id"
t.integer "role_id"
end
create_table "profiles_users", id: false, force: true do |t|
t.integer "profile_id"
t.integer "user_id"
end
create_table "role_types", force: true do |t|
t.string "name"
t.string "description"
t.datetime "created_at"
t.datetime "updated_at"
end
create_table "roles", force: true do |t|
t.string "name", null: false
t.string "description"
t.datetime "created_at"
t.datetime "updated_at"
t.integer "role_type_id"
t.string "display_name"
end
add_index "roles", ["name"], name: "index_roles_on_name", unique: true, using: :btree
create_table "users", force: true do |t|
t.string "username", default: "", null: false
t.string "encrypted_password", default: "", null: false
t.string "email", default: ""
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.datetime "created_at"
t.datetime "updated_at"
t.string "first_name"
t.string "last_name"
t.string "msisdn"
t.string "city"
t.string "address"
t.integer "e_bills_count", default: 0
t.string "notification_url"
t.string "notification_params", default: [], array: true
t.boolean "notification_post", default: true
t.string "legal_info"
t.string "greeting_message"
t.boolean "email_notification", default: false
t.string "website"
t.string "logo"
t.string "signature"
t.string "additional_notification_params", default: ""
t.string "currency"
end
так профиль некоторое поле, в котором 'admin' сохранен.? – Athar
Просьба предоставить нам некоторую информацию о том, как организован ваш db. Например, соответствующие части 'schema.rb' и/или файлов внутри' app/models/'. – EugZol
Как вы ожидаете, что кто-нибудь узнает ответ на этот вопрос, не взломав компьютер и не посмотрев на ваше приложение для рельсов? – max