Chris Kottom wrote: > > Second, putting error message text in the model is probably not what you > want to be doing. Your error messages are not part of your business > logic. > Most people put these things in the controller, although strictly > speaking, > they probably belong in the view (though Rails doesn't make it very easy > to > put them there and keep your code looking good). >
I'm reading AWDWR(3rd.) and in the first full example, which is a shopping cart, there is a user interface with CRUD operations for entering new Product's in the database. The example uses method calls to standard rails validation methods in the model, for example: validates_presence_of :description as well as a custom validation method: validate :price_must_be_at_least_a_cent protected def price_must_be_at_least_a_cent if price.nil? || price < .01 errors.add(:price, 'should be at least .01') end end That has an error message in the model, which seems contrary to your advice. Also, at the start of the section on validation, the authors say: ------ So, where to put the validation? The model layer is the gatekeeper between the world of code and the database. Nothing to do with our application comes out of the database or gets stored in the database that doesn't first go through the model. This makes models an ideal place to put validation;.... ------ If you have several controllers all accessing the database through the same model, then wouldn't you "get wet" duplicating the validation in each controller? -- 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 rubyonrails-talk@googlegroups.com To unsubscribe from this group, send email to rubyonrails-talk+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---