0

管理者のみがアプリケーションに登録されているすべてのユーザーを入力して表示できる、Ruby on Rails アプリケーションにダッシュボード機能を実装しています。ダッシュボードから、管理者はユーザーを非アクティブ化またはアクティブ化できます (特定の期間の場合があります)。is_active 列を持つ User テーブルがあります。テーブルのこの列にフラグを設定することで実行できます。詳しく説明していただけませんか。

以下は私のユーザーテーブルです。

create_table "users", :force => true do |t|
    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.boolean  "is_admin"
    t.boolean  "is_active"
    t.datetime "created_at",                             :null => false
    t.datetime "updated_at",                             :null => false
    t.string   "username"
  end

アプリケーションからのユーザーのアクティブ化と非アクティブ化の実装を手伝ってください(管理者はこれしかできません)

4

2 に答える 2

1

Userユーザーをアクティブ化および非アクティブ化するためのモデルで2つのメソッドを作成できます

class User < ActiveRecord::Base

 def activate_account!
   update_attribute :is_active, true
 end

 def deactivate_account!
   update_attribute :is_active, false
 end
end

is_active列のタイプはブール値であるuser.is_active?ため、レールによって生成されたメソッドを使用して、ユーザーのアカウントがアクティブかどうかを確認できます

于 2013-04-01T12:57:54.110 に答える
0

あなたのために、CanCanまたは別の認証gemを調べることをお勧めします. これについては、あなたが提供した移行でできることは何もないので、cancan の実装に関するこのスクリーンキャストを確認することをお勧めします。

http://railscasts.com/episodes/192-authorization-with-cancan

于 2013-04-01T12:35:23.113 に答える