Default values for model fields in a Ruby on Rails form

Posted by Callum Rogers on Stack Overflow See other posts from Stack Overflow or by Callum Rogers
Published on 2011-01-19T14:32:12Z Indexed on 2011/11/20 17:52 UTC
Read the original article Hit count: 460

I have a Model which has fields username, data, tags, date, votes. I have form using form_for that creates a new item and puts it into the database. However, as you can guess I want the votes field to equal 0 and the date field to equal the current date when it is placed into the database. How and where would I set/apply these values to the item?

I can get it to work with hidden fields in the form but this comes with obvious issues (someone could set the votes field to a massive number.

© Stack Overflow or respective owner

Related posts about ruby-on-rails

Related posts about ruby