添加自定义用户角色spree 1.3.1

时间:2013-01-15 12:55:09

标签: ruby-on-rails ruby ruby-on-rails-3.1 ruby-on-rails-3.2 spree

我正在使用 spree 1.3.1 设计宝石进行身份验证,我需要添加一个名为“合作伙伴”的 user_role “谁可以在管理区域看到订单,但无法创建/编辑/更新/删除任何订单。

提前致谢

2 个答案:

答案 0 :(得分:1)

拥有app/models/partner_ability.rb个文件。

然后对角色read -

使用以下基于partner权限的角色
class PartnerAbility
  include CanCan::Ability

  def initialize(user)
    user ||= User.new
    if user.has_role? "partner"
      can :read, Product
    end
  end
end

之后还要将以下内容添加到config/initializers/spree.rb -

Ability.register_ability(PartnerAbility)

答案 1 :(得分:-1)

In db/seed.rb file we can directly add admin user in spree..

for example 


puts 'SETTING UP DEFAULT USER LOGIN'

user1 = User.create! :title => 'Mr', :first_name => 'Jack', :last_name => 'Jackson', :email => 'jack@g.com', :password => '123qwe', :password_confirmation => '123qwe', :phone => '123452345'
puts 'New user created: ' << user1.first_name

user2 = User.create! :title => 'Mr', :first_name => 'Sev', :last_name => 'Raj', :email => 'sa@g.com', :password => '123qwe', :password_confirmation => '123qwe', :phone => '123452345'
puts 'New user created: ' << user2.first_name

puts 'New user created: ' << user4.first_name

user2.add_role :admin