Ruby on rails 未定义的方法Rails

Ruby on rails 未定义的方法Rails,ruby-on-rails,ruby-on-rails-3,devise,paperclip,Ruby On Rails,Ruby On Rails 3,Devise,Paperclip,大家好,型号中的Player.rb文件中的每个人,我已经设置了这个。。威奇做得很好 before_create :generate_random_hex private def generate_random_hex rand(9999) end Paperclip.interpolates :random_hex do |attachment, style| attachment.instance.random_hex end ha

大家好,型号中的Player.rb文件中的每个人,我已经设置了这个。。威奇做得很好

before_create :generate_random_hex

  private
    def generate_random_hex
  rand(9999)
    end

    Paperclip.interpolates :random_hex do |attachment, style|
    attachment.instance.random_hex
    end

    has_attached_file :avatar, :styles => { :profile => "300x300", :thumb => "100x100#"},
    :url  => "/assets/people/:id/:style/:basename.:extension",
    :path => ":rails_root/public/assets/people/:id/:style/:basename_:random_hex.:extension"

    validates_attachment_size         :avatar, :less_than    => 2.megabytes # Solo aceptar imágenes menores a 2 Mb.
    validates_attachment_content_type :avatar, :content_type => ['image/jpeg', 'image/pjpeg', 'image/png', 'image/x-png', 'image/gif']
问题是我有另一个控制器“更新”玩家的档案

我得到这个错误“未定义的方法'random_hex'for#”

下面是我如何尝试调用我认为需要使用Player.generate\u random\u hex的方法

或者我做错了什么

include Wicked::Wizard
  steps :personal_information, :experience, :skills, :references_achievements, :personal_profile, :paypal

  def show
    @player = current_user.player
    @player.clubs.build
    @player.links.build
    @player.references.build
    @player.achievements.build
    @player.citizens.build
    render_wizard

    authorize! :show, :player_steps
  end

  def update

    case step
      when :personal_information
        params[:player][:language_ids] ||= []
      when :experience
        params[:player][:selection_ids] ||= []
    end

    @player = current_user.player
    @player.update_attributes(params[:player])
    render_wizard @player

    authorize! :update, :player_steps
  end
试试这个:

Paperclip.interpolates :random_hex do |attachment, style|
  attachment.instance.generate_random_hex
end

# without `private`
def generate_random_hex
  rand(9999)
end