Tag: 更新属性

Update_all或update_attribute不更新列

我有一个用户可以通过电子邮件发送的状态报告,我希望在交付操作完成后更新列:sent_mail为true。 def send_status date = Date.today reports = current_user.reports.for_date(date) ReportMailer.status_email(current_user, reports, date).deliver reports.update_all(sent_mail: true) end 和表类 AddSentMailToReports < ActiveRecord::Migration def change add_column :reports, :sent_mail, :boolean, default: false end end 但是,在控制台中,sent_mail仍然设置为false。任何想法为什么这不起作用? 谢谢!

Ruby on Rails教程:如何在不确认密码的情况下编辑用户信息

我一直在研究Michael Hartl的Ruby on Rails教程。 目前,为了编辑任何用户属性,用户必须确认其密码。 有没有办法更新用户属性而不必这样做? 我的表单看起来像这样: ” users_controller.rb中的更新定义如下所示: def update if @user.update_attributes(params[:user]) flash[:success] = “Edit Successful.” redirect_to @user else @title = “Edit user” render ‘edit’ end end 目前,update_attributes操作失败。 谢谢!

使用has_secure_password Rails update_attributes

我正在一个用户可以拥有admin: true / false的项目中工作。 该应用程序只允许管理员用户登录系统,其他用户只是其设置只有管理员可以编辑的客户端。 这是某种商业应用程序。( Rails 3.2.13 ) 我想将这两个概念保存在同一个表中,因为将来可能会选择登录非管理员用户并与他们的配置文件进行交互,因此所有逻辑都已经实现。 我有这个User资源: ActiveRecord::Schema.define(:version => 20131204200554) do create_table “users”, :force => true do |t| t.string “name” t.string “surname” t.boolean “admin” t.string “password_digest” t.string “email” t.string “auth_token” end end 这是用户模型: class User < ActiveRecord::Base has_secure_password attr_accessible :name, :surname,:email, :password, :password_confirmation validates :name, presence:true, length: { maximum:50} validates :first_surname, […]