update-attributes

Updating `User` attributes without requiring password

三世轮回 提交于 2019-12-03 03:10:11
问题 Right now, users can edit some their attributes without having to enter their password because my validations are set up like this: validates :password, :presence =>true, :confirmation => true, :length => { :within => 6..40 }, :on => :create validates :password, :confirmation => true, :length => { :within => 6..40 }, :on => :update, :unless => lambda{ |user| user.password.blank? } However, after a user does this, their password is deleted - update_attributes is updating their password to "".

Updating `User` attributes without requiring password

安稳与你 提交于 2019-12-02 16:40:09
Right now, users can edit some their attributes without having to enter their password because my validations are set up like this: validates :password, :presence =>true, :confirmation => true, :length => { :within => 6..40 }, :on => :create validates :password, :confirmation => true, :length => { :within => 6..40 }, :on => :update, :unless => lambda{ |user| user.password.blank? } However, after a user does this, their password is deleted - update_attributes is updating their password to "". Here is my update definition: def update if @user.update_attributes(params[:user]) flash[:success] =

Carrierwave filename keeps changing on update_attributes

断了今生、忘了曾经 提交于 2019-11-30 20:24:39
I have model Company and company has mounted carrierwave uploader Logo. class Company < ActiveRecord::Base mount_uploader :logo, LogoUploader Images upload works, but I have an issue with update_attributes. When user wants to update only description or title of the company, but not to upload new image - filename value in DB is still being changed every time. Here is a simple example: 1.9.3-p545 :004 > a = Company.last 1.9.3-p545 :005 > a.update_attributes(:title => "test title 2") (0.4ms) BEGIN Company Exists (0.9ms) SELECT 1 AS one FROM `companies` WHERE (`companies`.`title` = BINARY 'test

Rails update_attributes using has_secure_password

ぐ巨炮叔叔 提交于 2019-11-30 19:38:46
问题 I am working in a project where users can either have admin: true / false . The application will only let admin users login in to the system, the other users are just clients whose settings only admins can edit. This is some sort of commerce application.( Rails 3.2.13 ) I would like to keep both concepts in the same table since in the future there will possibly be the option of logging in for non-admin users and interact with their profiles, so all the logic will be already implemented. I've

Carrierwave filename keeps changing on update_attributes

人盡茶涼 提交于 2019-11-30 05:01:21
问题 I have model Company and company has mounted carrierwave uploader Logo. class Company < ActiveRecord::Base mount_uploader :logo, LogoUploader Images upload works, but I have an issue with update_attributes. When user wants to update only description or title of the company, but not to upload new image - filename value in DB is still being changed every time. Here is a simple example: 1.9.3-p545 :004 > a = Company.last 1.9.3-p545 :005 > a.update_attributes(:title => "test title 2") (0.4ms)

Nested attribute update_attributes uses insert rather than update

泄露秘密 提交于 2019-11-30 01:30:16
I have a user and nested profile class as follows: class User < ActiveRecord::Base has_one :profile attr_accessible :profile_attributes accepts_nested_attributes_for :profile end class Profile < ActiveRecord::Base belongs_to :user attr_accessible :name end user = User.find(1) user.profile.id # => 1 user.update_attributes(profile_attributes: {name: 'some name'}) user.profile.id # => 2 I don't understand why rails is throwing away the old profile and creating a new one. Using user.profile.update_attributes({name: 'some name'}) just updates the current profile as expected. But in that case I'm

Nested attribute update_attributes uses insert rather than update

故事扮演 提交于 2019-11-28 22:19:40
问题 I have a user and nested profile class as follows: class User < ActiveRecord::Base has_one :profile attr_accessible :profile_attributes accepts_nested_attributes_for :profile end class Profile < ActiveRecord::Base belongs_to :user attr_accessible :name end user = User.find(1) user.profile.id # => 1 user.update_attributes(profile_attributes: {name: 'some name'}) user.profile.id # => 2 I don't understand why rails is throwing away the old profile and creating a new one. Using user.profile

Is the Rails update_attributes method the best choice for doing an update of a model in the database?

感情迁移 提交于 2019-11-28 21:22:24
def update @album = Album.find(params[:id]) if @album.update_attributes(params[:album]) redirect_to(:action=>'list') else render(:action=>'edit') end end A Rails 1.1.6 tutorial that I'm covering recommends using the update_attributes method for updating a model, as in the example code from my controller listed above. Looking at the Rails documentation I'm wondering why the update method would not have been preferred, especially since it is named so logically. Update takes an object id parameter and a set of attributes that otherwise work like update_attributes . So this (from AWDWR 3rd edition

How to “update_attributes” without executing “before_save”?

安稳与你 提交于 2019-11-27 14:29:32
问题 I have a before_save in my Message model defined like this: class Message < ActiveRecord::Base before_save lambda { foo(publisher); bar } end When I do: my_message.update_attributes(:created_at => ...) foo and bar are executed. Sometimes, I would like to update message's fields without executing foo and bar . How could I update, for example, the created_at field (in the database) without executing foo and bar ? 回答1: In rails 3.1 you will use update_column. Otherwise: In general way, the most

Is the Rails update_attributes method the best choice for doing an update of a model in the database?

↘锁芯ラ 提交于 2019-11-27 13:57:56
问题 def update @album = Album.find(params[:id]) if @album.update_attributes(params[:album]) redirect_to(:action=>'list') else render(:action=>'edit') end end A Rails 1.1.6 tutorial that I'm covering recommends using the update_attributes method for updating a model, as in the example code from my controller listed above. Looking at the Rails documentation I'm wondering why the update method would not have been preferred, especially since it is named so logically. 回答1: Update takes an object id