@lyfi2003 rails5.2 中 lock! 的机制有变化,导制以前正常的代码,时不时的出现(不是每次都出现),以什么办法兼容吗
RuntimeError (Locking a record with unpersisted changes is not supported. Use `save` to persist the changes, or `reload` to discard them explicitly.)
@jasl 嗯,我刚也试了,在 5.2 下正常,感谢
@jasl 我的 ruby 版本是 2.5.1 rails5.0.7.2
@jasl 用的是 role_core,和你 dummy 唯一不同的地方就是我没用 cancancan
def create
@role = Role.new(role_params)
if @role.save
redirect_to roles_url, notice: "Role was successfully created."
else
render :new
end
end
# Only allow a trusted parameter "white list" through.
private def role_params
params.require(:role).permit(:name, permissions_attributes: {})
end
@jasl 照着你的那个例子自己写的
@jasl 这样编辑权限的时候好像没生效
Parameters: {"utf8"=>"✓", "authenticity_token"=>"w0o9CGy+oR9bqZaPpmglcNnKrzRS+e7/LFTZOPePAOWrHHwbuMABqzolmhB3u0vVUSRSPqs77BwKHKU8iObC+Q==", "role"=>{"name"=>"j", "permissions_attributes"=>{"task"=>{"create"=>"1", "destroy"=>"0", "update"=>"0", "update_my_own"=>"1", "destroy_my_own"=>"1"}, "production"=>{"create"=>"1", "destroy"=>"0", "accept"=>"0", "read"=>"1", "read_public"=>"0"}, "topic"=>{"create"=>"1", "destroy"=>"1", "accept"=>"1"}}}, "commit"=>"Update Role", "id"=>"7"}
Role Load (0.5ms) SELECT `roles`.* FROM `roles` WHERE `roles`.`type` IN ('Role') AND `roles`.`id` = 7 LIMIT 1
Query Trace:
app/controllers/roles_controller.rb:47:in `set_role'
Unpermitted parameters: task, production, topic
(0.9ms) BEGIN
SQL (2.0ms) UPDATE `roles` SET `permissions` = NULL, `updated_at` = '2019-11-11 16:52:40' WHERE `roles`.`id` = 7
Query Trace:
app/controllers/roles_controller.rb:32:in `update'
(2.8ms) COMMIT
@jasl 这个地方参数要怎么设置,手动一个一个指定吗?
# Only allow a trusted parameter "white list" through.
private def role_params
params.require(:role).permit(:name, permissions_attributes: {})
end
下单成功,等待签收
还是运动好,跑步半年,完全没有控制饮食,瘦了十二斤
没试,纯猜
RestClient.post('http://example.com/resource',
{foo: 'bar'},
{content_type: "application/application/x-www-form-urlencoded"})
strip_tags 过滤所有 html 标签
@Nekor 格式合法在执行 to_date 嘛
2.5.1 :009 > "2018-02-30".to_date
Traceback (most recent call last):
1: from (irb):9
ArgumentError (invalid date)
/(^(\d{4})[-\/]{1}(\d{1,2})[-\/]{1}(\d{1,2})$)/ 简单粗暴,只能判断格式是否正确
cocoon
这不是微博
money_record = MoneyRecord.new
money_record.transaction do
money_record.save!
account.lock!
account.balance += money_record.money
account.save!
end
直接累加就好了,不用每次求和吧
redis-object 的 lock 与 activereocrd 的 lock 命名冲突,使用 with_lock 就悲剧了
redis-object 的 lock 和 rails 的 lock 命名冲突,比如 User.lock.find(1),本意是使用数据库的行级锁,这时调用的确是 redis-object 的 lock
好人卡 +1
现在市面上绝大多数的锁都能轻易被打开,你家就不装锁了吗?
家门口了,不参加说不过去
@huacnlee grape 里使用 RuCaptcha 吗
nokia 820
#1 楼 @huacnlee 请教下 devise 的 sign_in_and_redirect 方法
flash[:notice] = I18n.t "devise.omniauth_callbacks.success", :kind => "GitHub" if is_navigational_format?
sign_in_and_redirect @user, :event => :authenticatio
sign_in_and_redirect 登录成功后好像不能跳转,重写了 after_sign_in_path_for 函数也不行。假设第三方登录按钮在网站首页,登录成功还是在首页,怎么跳转到用户主页