update-attributes

ruby-on-rails: update_attributes overrides model validations?

I have a typical, Post model: class Post< ActiveRecord::Base validates_presence_of :user_id #Line 1 validates_presence_of :title,:body #Line 2 in the controller, I have: def create if request.post? if login_required @post = Post.new(params[:...

Rails: saving a string on an object -- syntax problem?

Hey there, I am trying to write a simple function to clean a filename string and update the object. When I save a test string it works, but when I try to save the string variable I've created, nothing happens. But when I return the string, the output seems to be correct! What am I missing? def clean_filename clean_name = file...

Rails: update_attribute vs update_attributes

Object.update_attribute(:only_one_field, "Some Value") Object.update_attributes(:field1 => "value", :field2 => "value2", :field3 => "value3") Both of these will update an object without having to explicitly tell AR to update. Rails API says: for update_attribute Updates a single attribute and saves the record without going throug...

Rails - update_attributes coming up against validations

So I've got a user model, with login, email address, password, password confirmation, name, avatar (picture), etc. There are validations on the first 5, basically stating that all 5 need to exist in order to create a new model. However, this causes problems for me where updates are concerned. I've got an edit page, where the user can o...

how to update_attributes with the conditions?

I need to update attributes but only for rows with the specific conditions like ["recipient_id = ? and inbox_id = ? and status='unread'", current_user.id, @inbox.id] How do I do it? ...

what `update_attribute` return if it get failed?

Hi All, I have following piece of code @user = User.find(params[:id]) if (@user.activation_status == "active") #some code here @user.update_attribute('activation_status' ,'inactive') # Line 44 #send mail to user that his account is Acivated else end Is there any chance that Line 44 get fail because of any reason (for e...

rails validation on accepts_nested_attributes_for and habtm association in an update resets the association

In rails 2.3.8 I am having trouble with validations on a accepts_nested_attributes_for association if I loop through or even inspect the habtm association in validation the lessons are loaded and any updates are lost. For example, I have the following schema: ActiveRecord::Schema.define(:version => 20100829151836) do create_table "att...

nested model form and update_attributes

hi, I have a nested-model form with a one-to-many relationship between a class Project and class TeamMember, and in the controller, an update function like : @project = Project.find(params[:id]) @project.update_attributes(params[:project]) Now, I'd like to set some fields that are not set in the form for some of the t...

update_attributes not working for many-to-many nested attributes

I have some nested attributes in some models as such: class Employee < ActiveRecord::Base has_one :user, :as => :user_role, :dependent => :destroy accepts_nested_attributes_for :user, :allow_destroy => true end class User < ActiveRecord::Base has_one :person, :as => :person_role, :dependent => :destroy belongs_to :user_role, :p...