0

我正在使用spree 1.3.1Devise gem进行身份验证,我需要添加一个名为“合作伙伴”的用户角色,他可以在管理区域查看订单,但不能创建/编辑/更新/删除任何订单。

提前致谢

4

2 回答 2

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)
于 2013-01-15T13:45:17.373 回答
-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
于 2013-01-25T12:40:27.950 回答