# Getting messages from Model

**URL:** <https://discuss.rubyonrails.org/t/getting-messages-from-model/18060>\
**Category:** rubyonrails-talk\
**Created:** [September 12, 2007, 4:43am UTC](https://discuss.rubyonrails.org/t/getting-messages-from-model/18060 "2007-09-12T04:43:20Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![raghukumar](https://avatars.discourse-cdn.com/v4/letter/r/858c86/32.png) [@raghukumar](https://discuss.rubyonrails.org/u/raghukumar)\
**Post date:** [September 12, 2007, 4:43am UTC](https://discuss.rubyonrails.org/t/getting-messages-from-model/18060/1 "2007-09-12T04:43:20Z")

</div>

Hi Shandy,

you do something like this in your controller, (assume User is the name of model)

class MyController \< ApplicationController &nbsp;&nbsp;def create # do what ever validation you want for the incoming parameters, and i'll assume params[:user] contains all attribute necessary for creation of user user = User.new(params[:user])

&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;begin &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;x.save! &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;rescue Exception =\> e &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts x.errors['password'] # this will print the error message you have given, so do what ever you want with this( i am just printing) &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;# password is the field name in database table, which can be any column you want. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;puts e.message # even this will contains the error message. &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;end &nbsp;&nbsp;end end
