Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/google-maps/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 从Desive User创建客户_Ruby On Rails_Devise - Fatal编程技术网

Ruby on rails 从Desive User创建客户

Ruby on rails 从Desive User创建客户,ruby-on-rails,devise,Ruby On Rails,Devise,如何创建一个customer类?我想成为角色为1的Desive用户 我有我的用户模型: class User < ActiveRecord::Base enum role: [:user, :customer, :admin, :producer] after_initialize :set_default_role, :if => :new_record? def set_default_role self.role ||= :user end #

如何创建一个customer类?我想成为角色为1的Desive用户

我有我的用户模型:

class User < ActiveRecord::Base
  enum role: [:user, :customer, :admin, :producer]
  after_initialize :set_default_role, :if => :new_record?

  def set_default_role
    self.role ||= :user
  end

  # Include default devise modules. Others available are:
  # :confirmable, :lockable, :timeoutable and :omniauthable, :registerable
  devise :invitable, :database_authenticatable, :confirmable, :registerable,
         :recoverable, :rememberable, :trackable, :validatable
end
但是,我如何修改我的客户模型,使自己知道他是role=1的用户,这样我只能得到这样的客户:

# GET /customers
def index
  @customers = Customer.where(:role => 1).page(params[:page])
end
@customers = Customer.all

如果您确实需要
Customer.all
您应该查找STI(单表继承),它已经解决了您试图执行的操作

谢谢,我会查看它。
@customers = Customer.all