John Merlino wrote:
> Hey all,
> 
> What if I want to check a column in a table to see if a value exists and
> if it doesn't, then update the existing record with the specified value
> and if it does exist increment by 1 from the previous incrementation of
> the value. And do it using the model (or controller if it's unable to be
> done in the model). Something like this:
> 
> def test!
>      update_attributes :student_number =>
>      if student_number.array.include?(2001)
>        Student.student_number.first(:order => "student_number
> DESC").student_number + 1
>      else
>        2001
>    end
>   end
> 
> Can this be done?

Yes, but you *really* don't want to.  Just use an autoincrement field in 
the DB (perhaps the id field).

John, I've noticed that most of your posts here are on questions that 
could have been answered by a quick look at the Rails Guides or 
Programming Ruby.  May I suggest that you spend less time posting and 
more time reading documentation?

 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.

Reply via email to