我有我已經設置制定了管理用戶賬號等樣品的Rails 3.1.1應用Devise in Rails 3.1.1,通過種子添加管理員用戶?
我跑到下面的步驟來管理員屬性添加到用戶表:
$ rails generate migration add_admin_to_user admin:boolean
增加了以下我的遷移:
class AddAdminToUser < ActiveRecord::Migration
def self.up
add_column :users, :admin, :boolean, :default => false
end
def self.down
remove_column :users, :admin
end
end
我然後跑了分貝:遷移,並添加以下到我的佈局文件:
<% if current_user.admin? %>
You are ADMIN.
<%end %>
然後,添加我使用了以下的種子文件的第一管理用戶:
puts 'SETTING UP DEFAULT USER LOGIN'
user = User.create! :name => 'Test User', :email => '[email protected]', :password => 'password', :password_confirmation => 'password'
puts 'New user created: ' << user.name
這一工作,所以再與管理員字段適於它:
puts 'SETTING UP DEFAULT USER LOGIN'
user = User.create! :name => 'Test User', :email => '[email protected]', :password => 'password', :password_confirmation => 'password', :admin => 'true'
puts 'New user created: ' << user.name
上述種子文件工作,但管理標誌沒有顯示。
我錯過了什麼嗎?
更新:模型/用戶/ RB
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :token_authenticatable, :encryptable, :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
# Setup accessible (or protected) attributes for your model
attr_accessible :name, :email, :password, :password_confirmation, :remember_me
end
你確定你添加管理員場到attr_accessible宏? – lucapette
不!我將如何檢查? – dannymcc
將模型定義添加到問題 – lucapette