search for: update_attribute

Displaying 20 results from an estimated 504 matches for "update_attribute".

Did you mean: update_attributes
2005 Nov 30
8
nested attributes with update_attributes()
Hi, I am trying to use the update_attributes on object with nested attributes and I am getting the following error: ProductPrice expected, got HashWithIndifferentAccess Here''s the situation (simplified): class Product < ActiveRecord::Base belongs_to :productPrice end class ProductPrice < ActiveRecord::Base has_one...
2006 Jul 11
3
update_attributes and save!
I notice that ActiveRecord::Base.update_attributes() calls save(). What if I want to get an exception if the save fails? Is there a way to get the update_attributes() function plus the save! function? Thanks, Wes -- Posted via http://www.ruby-forum.com/.
2007 Jun 30
3
transactions with two models
...s each in a different table of the same database. Suppose they are apples and oranges tables. How do I write this? Do I need to be as elaborate as this and will it work? apple = Apple.find(:first) orange = Orange.find(:first) Apple.transaction(apple) do Orange.transaction(orange) do apple.update_attributes(params[:apple]) orange.update_attributes(params[:orange]) end end Or can I just write something much simpler like this? Apple.transaction(apple, orange) do apple.update_attributes(params[:apple]) orange.update_attributes(params[:orange]) end Will the above be a problem since orange is...
2006 Dec 08
9
How to update partial attributes of a object from a form?
...ibutes. I divide these attributes into 4 groups... namely ''general info'', ''personal info'', ''contact info''... and I make separate forms to edit these 4 different group attributes. The problem is when I update one group of attributes using: @user.update_attributes(params[:user]) now, because the params[:user] hash only contains partial attributes that @user has, so this can''t work. now, i use @user.update_attribute(:address, params[:user][:address]) @user.update_attribute(:city, params[:user][:city]) @user.update_attribute(:state, para...
2006 Jan 17
2
update_attribute and validations
Just in case it saves someone else the several hours of insanity I just went through, update_attributes will not save unless the model validations are satisfied, but update_attribute (the singular form) will save the attribute to the database even if the model validations would fail! This appears to be a feature, not a bug (http://api.rubyonrails.com/classes/ActiveRecord/Base.html) although it...
2006 Jun 08
5
update only the join table in a HABTM - how?
...ies for users. in one part, I want to be able to define gallery access for a user seperate from updating any of the user info. I have this function: def edit_access @user = User.find(params[:id]) @user.galleries = Gallery.find(params[:gallery_ids]) if params[:gallery_ids] if @user.update_attributes(params[:user]) flash[:notice] = ''Account was successfully updated.'' redirect_to :action => ''list'' else @galleries = Gallery.find(:all) render :action => ''manage_access'' end end The function works and upd...
2011 May 21
1
Consequences of overriding update_attribute to force validation?
...gems use it and in one case I was just burned. I do not want invalid objects in my database under any circumstances, since the rest of my code rationally depends on validations - e.g. I don''t check for null associations when the association is validated to be there. For the uninitiated, update_attribute: 1) Does not ever validate the object, causing a massive hole in your validation schemes. For instance, if a validation depends on anything you update with update_attribute, that validation will not work. 2) Updates ALL fields if the object has been modified. @user.email = ''invalidemail...
2006 Jan 04
0
update_attribute works, update_attributes doesn''t, why?
Hello again... so I narrowed my problem down. For some reason, while using login_generator, any User object I pull from the DB can be updated one attribute at a time using update_attribute, but when I try and do update_attributes it fails every time. Is this a limitation with login_generator that I don''t know about, or is there a way around this? I also tried the .update method and that fails too. My logs show that it never even tries the UPDATE sql command, or any kind...
2006 Feb 27
4
update_attribute with Validation?
Does anyone know of a way to update individual attributes with validation? update_attribute disables the validation checks in the record model, so I''m wondering if there''s a workaround for this. In my application, I want to allow the user to update some or all the attributes without having to enter :password and :password_confirmation, both of which are subject to va...
2008 Aug 26
1
transaction not working with update_attributes!
I am trying to wrap the updating of two models in a transaction and when the transaction fails it is not rolling back. My method is : def update_attributes(user,params) @user = user @company = user.company begin User.transaction do @user.update_attributes!(params[:user]) @company.update_attributes!(params[:company]) end true rescue false end end In the above method , if @user fails @comp...
2009 Feb 03
1
update_attributes! does not update nested model
Hi! I have updated my app to rails 2.3. I have form that has few nested models and I am happy that I can just write accepts_nested_attributes_for :tasks, :allow_destroy => true, but update_attributes! does not update my nested model. I have tried update_attributes, and it works. Any ideas? Few lines from log: update_attributes: SQL (0.1ms) BEGIN Education Update (0.3ms) UPDATE `educations` SET `institution` = ''ins'', `updated_at` = ''2009-02-03 13:34:08'&...
2006 Jun 27
6
Custom action on Active Record Validation Failure?
Instead of having it highlight the bad fields when you enter in a record that fails validation, is there a way to make it do an action? I''m looking for something like this: validates_uniqueness_of :user_id,:url => {:controller => "headline", :action => "index"} so that on failing the uniqueness check, it would go to the headline controller. --
2006 May 02
9
Updating only one field
At present, I use an update like this to set the user''s last login time: authenticated_user.update_attribute(:last_login, Time.now) However, this calls the following, updating all fields: UPDATE users SET `last_login` = ''2006-05-02 13:27:41'', `hashed_password` = .... Is there any way I can tell ActionRecord to only update the one field? I don''t really want the hashed_passwo...
2006 Dec 29
2
update_attributes fails: ReadOnlyRecord
I''m trying to update a record, but it just stops with "ActiveRecord::ReadOnlyRecord". I don''t understand why, because I never wanted my model to be read only. Relevant code: Controller: def edit @project = find_project if request.post? @project.update_attributes(params[:project]) if @project.save flash[:message] = _(''Project was updated'') redirect_to :action => ''index'' return else flash[:warning] = _(''Could not update project'') end end end Mo...
2008 Feb 08
2
update_Attributes stale Object error
Hi, IN one of my unit tests I get an ActiveRecord::StaleObjectError: Attempted to update a stale object object.save! in object I have apart from other stuff an after_save method, which calls object.assosication.update_attributes(...) If I remove that line from my code my tests succeeds. Unfortunetly, I do not understand why an update_attributes call can generate an StaleObjectError. Maybe anybody can explain this to me? Thanks a lot in advance. Volker --~--~---------~--~----~------------~-------~--~----~ You received...
2006 Jan 25
2
Update join_table attributes
...it''s exactly the same setup as the articles<->articles_users<->users example on p240. The habtm relationship is setup fine. I can see the linked data in instances of the objects. The problem, though, is that I can''t update the extra columns in the join table using update_attributes. This is a well documented shortcoming, and the solution everyone talks about is to override the update_attributes code. The code (see the comments @ http://tinyurl.com/ey5qd) starts like so: module ActiveRecord module Associations class HasAndBelongsToManyAssociation def update_a...
2007 May 21
7
How do I stop a column being updated by model.save?
One of my models has a column that is updated very frequently from a separate process, so it is important that when a record is saved in rails, this column should be left alone. In the update method of the controller I have: @record = MyModel.find(params[:id]) @record.update_attributes(params[:my_model]) params[:my_model] doesn''t have a reference to the column I''m talking about, however, the UPDATE statement produced by update_attributes will still assign a value to this column. Even though its unlikely, if the separate process updates the record in the time...
2006 Mar 29
5
How to skip password validation when updating other fields?
...''s login name, I guess I have the next options: 1) user = User.find(session[:user_id]) user.login = params[:login] user.save => Won''t work because the password and password_confirmation validations hit. 2) user = User.find(session[:user_id]) user.login = params[:login] user.update_attributes(:login => params[:login] ) => Won''t work because the password and password_confirmation validations hit. 3) user = User.find(session[:user_id]) user.login = params[:login] user.update_attribute(:login, params[:login] ) => Updates the fiels to db, but passes all validations. No...
2006 Jul 02
5
Question about setting field values for a belongs_to model
...This sounds to me like it should lead to the description of the skill being updated in the database, and indeed an update statement is in the log, but with the original value. The description of the skill is not updated in the database. Instead, this works @applicant.skills.find(id_of_skill).update_attributes(:description => ''new description'') ...other processing @applicant.save So somewhere my intuition is wrong. How should I think about this? Why does the straightforward statement not work? Code to pour over is below. This is on ruby 1.8.4 (2005-12-24) [i386-linux] / Rails 1...
2007 Jan 10
6
Updating an attribute in db
...ecord. I use this code to invoke a method from controller: <%= button_to "Change", { :action => "edit", :id => prog.id_prog } %> My method looks like this (just a simple one - to set the salary attribute to 1000) def edit prog = Prog.find(params[:id]) prog.update_attribute(:salary, 1000) redirect_to :action => ''list'' end However after a list view is shown again the change is not made to the database. I do not get it, as find returns the proper record and update_attribute returns true. What may be wrong? Thanks in advance -- Posted via htt...