小编Cra*_*ney的帖子

Rails 4:跳过回调

我的应用程序中有拍卖和出价对象,当有人按下BID BUTTON然后调用创建出价的BID CREATE控制器,然后在拍卖对象上做一些其他事情:

BIDS控制器 - >创建

@auction.endtime += @auction.auctiontimer
@auction.winner = @auction.arewinning 
@auction.save
Run Code Online (Sandbox Code Playgroud)

拍卖模型

before_update :set_endtime

def set_endtime
   self.endtime=self.starttime+self.auctiontimer
end
Run Code Online (Sandbox Code Playgroud)

所以问题是:在这个特定的@ auction.save中,C如何才能跳过"回调前"

ruby ruby-on-rails callback

8
推荐指数
2
解决办法
2万
查看次数

密码不能为空,Bcrypt

在我的Rails应用程序上安装Bcrypt之后,存在验证问题:password =>"不能为空",即使填写了表单:

这是我的用户模型

class User < ActiveRecord::Base   
  before_save { self.email = email.downcase }   
  validates :username, presence: true, length: { maximum: 50 }

  VALID_EMAIL_REGEX = /\A[\w+\-.]+@[a-z\d\-.]+\.[a-z]+\z/i

  validates :email, presence:   true,
            format:     { with: VALID_EMAIL_REGEX },
            uniqueness: { case_sensitive: false }   
  has_secure_password   
  validates :password, length: { minimum: 6 } 
end
Run Code Online (Sandbox Code Playgroud)

我已尝试过rails c,现在出现了摘要:

User.create:

User.create(username: "Riprova", email:"testato@gmail.com", password: "nonfunzia", password_confirmation:"nonfunzia")

<User id: 15, username: "Riprova", name: nil, surname: nil, email: "testato@gmail.com", gender: nil, birth: nil, created_at: "2013-08-11 15:35:03", updated_at: "2013-08-11 15:35:03", password_digest: "$2a$10$Q/5qtZYDXRcFsUWgve3JL.wui4hSHLhGgsuO0C6TTkBY..."> …
Run Code Online (Sandbox Code Playgroud)

ruby-on-rails bcrypt

3
推荐指数
1
解决办法
4380
查看次数

标签 统计

ruby-on-rails ×2

bcrypt ×1

callback ×1

ruby ×1