# How to add validation to in\_place\_editor

**URL:** <https://www.ruby-forum.com/t/how-to-add-validation-to-in-place-editor/99059>\
**Category:** Rails\
**Created:** [July 20, 2006, 1:38am UTC](https://www.ruby-forum.com/t/how-to-add-validation-to-in-place-editor/99059 "2006-07-20T01:38:19Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [July 20, 2006, 1:38am UTC](https://www.ruby-forum.com/t/how-to-add-validation-to-in-place-editor/99059/1 "2006-07-20T01:38:19Z")

</div>

I have a simple question, but can’t seem to figure this out.

I added an in place editor field and didn’t like how it didn’t use  
the save method. It uses the update\_attribute method which does not  
run validation, etc. So I just added the method in my controller myself:

def set\_event\_url  
begin  
@event = Event.find params[:id]  
@event.url = params[:value]  
@event.save  
render :text =\> @event.send(:url)  
rescue Exception =\> error  
render :text =\> error  
end  
end

The problem is that if there is an error that is rescued it sets that  
field to the output of the error. What I’d like it to do is pop up a  
little javascript window like it does if an exception goes uncaught.

Any ideas?

Thanks for your help.

Thank You,  
Ben J.  
E: removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![benjohnson](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/3ec8ea/32.png) [@benjohnson](https://www.ruby-forum.com/u/benjohnson)\
**Post date:** [July 20, 2006, 1:52am UTC](https://www.ruby-forum.com/t/how-to-add-validation-to-in-place-editor/99059/2 "2006-07-20T01:52:26Z")

</div>

On Jul 19, 2006, at 6:35 PM, Ben J. wrote:

> ```
> @event.url = params[:value]
> 
> ```
> 
> uncaught.
> 
> * * *
> 
> Rails mailing list  
> removed\_email\_address@domain.invalid  
> [http://lists.rubyonrails.org/mailman/listinfo/rails](http://lists.rubyonrails.org/mailman/listinfo/rails)

Better yet, is it possible to simply update a tag on the page and  
keep the invalid value. Like the following:

def set\_event\_url  
begin  
@event = Event.find params[:id]  
@event.url = params[:value]  
@event.save  
render :text =\> @event.send(:url)  
rescue Exception =\> error  
render :update do |page|  
page.replace\_html ‘notices’, error  
end  
end  
end

What happens there, is that the element on the page gets updated but  
then the field value is replaced by the javascript that updates that  
field. Any ideas how I can just keep the field value to the same  
value that caused the error?

Thanks for the help.

Thank You,  
Ben J.  
E: removed\_email\_address@domain.invalid
