# Update\_attributes and validation

**URL:** <https://www.ruby-forum.com/t/update-attributes-and-validation/162756>\
**Category:** Rails\
**Created:** [March 13, 2009, 1:00pm UTC](https://www.ruby-forum.com/t/update-attributes-and-validation/162756 "2009-03-13T13:00:42Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nilez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/34f0e0/32.png) [@nilez](https://www.ruby-forum.com/u/nilez)\
**Post date:** [March 13, 2009, 1:00pm UTC](https://www.ruby-forum.com/t/update-attributes-and-validation/162756/1 "2009-03-13T13:00:42Z")

</div>

hi all,

```
I am updating 50 records on one page with update_attributes method

```

,my validations are

validates\_numericality\_of :year, :greater\_than\_or\_equal\_to =\> 1900,  
:less\_than\_or\_equal\_to =\> 2028, :message =\> “Year must be between 1900  
and 2028”  
valdate\_presence\_of:title  
valdate\_presence\_of:price

id title year price  
1 James bond 2008 $100  
2 zoro the mask 1978 $ 50  
.  
.  
.  
.  
50 don 2000 $400

if I provide wrong input for one say year “1800” for “don” and correct  
for “james bond” year as “2000” it updates James bond ,correctly but do  
not show validation message for “don” on my page. I want to display  
message how can i do that

---

<div class="post-metadata">

**Author:** ![nilez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/34f0e0/32.png) [@nilez](https://www.ruby-forum.com/u/nilez)\
**Post date:** [March 13, 2009, 1:45pm UTC](https://www.ruby-forum.com/t/update-attributes-and-validation/162756/2 "2009-03-13T13:45:21Z")

</div>

try with update\_attributes! (which internally uses ‘save!’)

On Fri, Mar 13, 2009 at 2:00 PM, Nilesh K. \<  
removed\_email\_address@domain.invalid\> wrote:

> and 2028"  
> 50 don 2000 $400
> 
> ## if I provide wrong input for one say year “1800” for “don” and correct for “james bond” year as “2000” it updates James bond ,correctly but do not show validation message for “don” on my page. I want to display message how can i do that
> 
> Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> 
> >

## –

Thanks & Regards,  
Sumanth Krishna. A  
+358 40 3276564

Blogs:  
TwinclingCommunity:

> **[TechSavvy](http://sumanthtechsavvy.blogspot.com/)**
>
> Technical Blog

[http://www.twincling.org/node/227](http://www.twincling.org/node/227)

[http://yourway2health.blogspot.com/](http://yourway2health.blogspot.com/)  
[http://www.osef.twincling.org](http://www.osef.twincling.org)

---

<div class="post-metadata">

**Author:** ![nilez](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/34f0e0/32.png) [@nilez](https://www.ruby-forum.com/u/nilez)\
**Post date:** [March 14, 2009, 6:04am UTC](https://www.ruby-forum.com/t/update-attributes-and-validation/162756/3 "2009-03-14T06:04:21Z")

</div>

Sumanth Krishna wrote:

> try with update\_attributes! (which internally uses ‘save!’)
> 
> On Fri, Mar 13, 2009 at 2:00 PM, Nilesh K. \<  
> removed\_email\_address@domain.invalid\> wrote:
> 
> > and 2028"  
> > 50 don 2000 $400
> > 
> > ## if I provide wrong input for one say year “1800” for “don” and correct for “james bond” year as “2000” it updates James bond ,correctly but do not show validation message for “don” on my page. I want to display message how can i do that
> > 
> > Posted via [http://www.ruby-forum.com/](http://www.ruby-forum.com/).
> > 
> > >
> 
> ## –
> 
> Thanks & Regards,  
> Sumanth Krishna. A  
> +358 40 3276564
> 
> Blogs:  
> TwinclingCommunity:
> 
> [http://sumanthtechsavvy.blogspot.com/](http://sumanthtechsavvy.blogspot.com/)  
> [http://www.twincling.org/node/227](http://www.twincling.org/node/227)
> 
> [http://yourway2health.blogspot.com/](http://yourway2health.blogspot.com/)  
> [http://www.osef.twincling.org](http://www.osef.twincling.org)  
> hi

I have used update\_attributes! it shows validation message

ActiveRecord::RecordInvalid in BookController#edit\_book

Validation failed: Year should be a above 1900

on different page ,but i want that message must be displayed on same  
page on top  
my controller look like this

def edit\_book  
if request.post?

# code for update data ie “update\_attribute!” method

end  
@books = Book.find(:all)  
end

and I have view named “edit\_book.html.erb”
