bingo bob wrote: [...] > Just a point that I've always found slightly confusing. If I've > understood correctly this line.. > > if @record.update_attributes(params[:sample]) > > actually *does* the updating part, believe the if is there for error > trapping and returning. > > I've always struggled as to why that line starts with the word "if", am > I reading it right in that the line basically does the update_attributes > "if" it can? Maybe I'm just thinking about it wrong but it doesn't seem > intuitive to me.
You are indeed thinking about it completely wrong. Think in the general case about how if EXPR works in Ruby: it evaluates EXPR and then looks to see if it returns true or false. So if x > 5 evaluates x > 5 and checks its return value. Likewise, if @record.update_attributes(params[:sample]) evaluates @record.update_attributes(params[:sample]) and checks its return value. It *happens* that in the course of the evaluation, a database operation is attempted, but that's immaterial to the if statement. Best, -- Marnen Laibow-Koser http://www.marnen.org [email protected] -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

