# Validation with in\_place\_edit\_for

**URL:** <https://www.ruby-forum.com/t/validation-with-in-place-edit-for/56544>\
**Category:** Rails\
**Created:** [April 1, 2006, 12:10am UTC](https://www.ruby-forum.com/t/validation-with-in-place-edit-for/56544 "2006-04-01T00:10:04Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [April 1, 2006, 12:10am UTC](https://www.ruby-forum.com/t/validation-with-in-place-edit-for/56544/1 "2006-04-01T00:10:04Z")

</div>

i’ve got an in place edit text box for some of my fields. my model has  
validates\_presence\_of for the field but nothing happens. it works fine  
in the scaffold when using the edit page, but nowhere else.

anyone have a solution to this?

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [June 25, 2006, 1:56am UTC](https://www.ruby-forum.com/t/validation-with-in-place-edit-for/56544/2 "2006-06-25T01:56:36Z")

</div>

There was no reply to this question but it must be a common requirement.  
Is  
there a good solution?

How would one get a validates\_\*\*\* from the model to apply when using  
in\_place\_edit\_for?

– Brian

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [June 25, 2006, 7:35pm UTC](https://www.ruby-forum.com/t/validation-with-in-place-edit-for/56544/3 "2006-06-25T19:35:18Z")

</div>

The In\_place\_editor still uses the callbacks like before\_update, so  
maybe your could force your validation requirements to fire that way.

–  
Timothy J.

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [March 20, 2007, 6:05am UTC](https://www.ruby-forum.com/t/validation-with-in-place-edit-for/56544/4 "2007-03-20T06:05:27Z")

</div>

I’ve just created a custom in\_place\_edit that validates the model and  
display the error message in javascript alert box.

[http://www.pluitsolutions.com/2007/03/20/custom-in\_place\_edit-with-validation/](http://www.pluitsolutions.com/2007/03/20/custom-in_place_edit-with-validation/)

Herryanto S.

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [March 21, 2007, 6:32am UTC](https://www.ruby-forum.com/t/validation-with-in-place-edit-for/56544/5 "2007-03-21T06:32:24Z")

</div>

Hi,  
I followed the above link and try using that link, but i am not getting  
any alert box, and still its taking the blank one in to the database, SO  
wat should i do for this???

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [March 21, 2007, 8:05am UTC](https://www.ruby-forum.com/t/validation-with-in-place-edit-for/56544/6 "2007-03-21T08:05:32Z")

</div>

Hi,  
I restarted the server, but till i am not getting, later i added the  
validates\_presence\_of :name then it worked for me, I got the alert box  
saying that it shouldn’t be blank, so its working, but wen i try to edit  
by not giving blank with another value, then also its giving an alert  
box that it shouldn’t be blank, and am even not able to add a new one,  
so wat should i do for this??

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [March 22, 2007, 2:22am UTC](https://www.ruby-forum.com/t/validation-with-in-place-edit-for/56544/7 "2007-03-22T02:22:49Z")

</div>

Naga harish Kanegolla wrote:

> Hi,  
> I restarted the server, but till i am not getting, later i added the  
> validates\_presence\_of :name then it worked for me, I got the alert box  
> saying that it shouldn’t be blank, so its working, but wen i try to edit  
> by not giving blank with another value, then also its giving an alert  
> box that it shouldn’t be blank, and am even not able to add a new one,  
> so wat should i do for this??

Naga, I’m not sure what went wrong though, it’s a bit hard to know  
without looking at the codes. Use firebug, check out the Ajax request  
generated, put a print statement in your codes, look at the log files,  
you probably would be able to see something helpful.

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [March 22, 2007, 6:26am UTC](https://www.ruby-forum.com/t/validation-with-in-place-edit-for/56544/8 "2007-03-22T06:26:15Z")

</div>

Hi,  
Thanks a lot, its working fine , i am sorry that i have given the  
wrong column name for validates\_presence\_of in the model,its good, and  
every body liked that,  
and i would ask u one more thing, is there any alert box custom code for  
validating the Ajax form, like if i click a link an ajax form appears  
and if i give a blank and submit its not taking the value in the  
database but i should get an alert saying that it is blank,

Thanks in Advance,  
Harish

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [March 21, 2007, 7:40am UTC](https://www.ruby-forum.com/t/validation-with-in-place-edit-for/56544/9 "2007-03-21T07:40:40Z")

</div>

Naga harish Kanegolla wrote:

> Hi,  
> I followed the above link and try using that link, but i am not getting  
> any alert box, and still its taking the blank one in to the database, SO  
> wat should i do for this???

Hey naga, I forgot to mention that you’ll need to restart your mongrel  
server. Did you do that?

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [April 1, 2007, 8:07am UTC](https://www.ruby-forum.com/t/validation-with-in-place-edit-for/56544/10 "2007-04-01T08:07:37Z")

</div>

Laurynas,

Please add append the following lines to custom\_in\_place\_editing.rb, I  
updated the code snippet yesterday to fix caching issue on Rails 1.2,  
which causes the entry to be blank, after the error message alert. But I  
forgot to copy a few lines below.

ActionController::Base.class\_eval do  
include ActionController::Macros::CustomInPlaceEditing  
end

Harris, I’m not sure what you meant though, sorry.

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [April 1, 2007, 12:51pm UTC](https://www.ruby-forum.com/t/validation-with-in-place-edit-for/56544/11 "2007-04-01T12:51:10Z")

</div>

Herryanto,

thanks a lot for a quick reply! Now it works fine.

Laurynas

On 1 Apr, 09:07, Herryanto S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [April 1, 2007, 12:11am UTC](https://www.ruby-forum.com/t/validation-with-in-place-edit-for/56544/12 "2007-04-01T00:11:52Z")

</div>

Looks like a nice piece of code 😉 I’m rails newbie and have some  
problems integrating it. I’ve created custom\_in\_place\_editing.rb in my  
lib/ and added include to my environment.rb, but I’m still getting  
‘uninitialized constant’ error if I add  
‘in\_place\_edit\_with\_validation\_for’ to my controller. I did server  
restart. Do you have any idea?

Thanks in advance,  
Laurynas

On Mar 20, 8:05 am, Herryanto S. \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [April 1, 2007, 1:23pm UTC](https://www.ruby-forum.com/t/validation-with-in-place-edit-for/56544/13 "2007-04-01T13:23:13Z")

</div>

Maybe I replied too quickly 🙂 Now I noticed, that I’m getting  
“undefined method ‘query\_cache’” exception if validation fails. If I  
comment out  
“object.to\_s.camelize.constantize.query\_cache.clear\_query\_cache”, I  
get correct validator error message, but then blank value is shown.  
That’s on Rails 1.2.3.

Laurynas

On 1 Apr, 09:07, Herryanto S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [April 1, 2007, 6:13pm UTC](https://www.ruby-forum.com/t/validation-with-in-place-edit-for/56544/14 "2007-04-01T18:13:28Z")

</div>

Laurynas,

I forgot that I’m using RailsOnEdge. You are right, there’s no  
query\_cache in rails 1.2.3. I’ve applied the patch to handle that.

Please re-copied the source codes from the same place:  
[http://www.pluitsolutions.com/2007/03/20/custom-in\_place\_edit-with-validation/](http://www.pluitsolutions.com/2007/03/20/custom-in_place_edit-with-validation/)

Sorry for the confusion, and thanks for reporting that.

---

<div class="post-metadata">

**Author:** ![jjkiesch](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/bc79bd/32.png) [@jjkiesch](https://www.ruby-forum.com/u/jjkiesch)\
**Post date:** [April 1, 2007, 9:39pm UTC](https://www.ruby-forum.com/t/validation-with-in-place-edit-for/56544/15 "2007-04-01T21:39:24Z")

</div>

Herryanto,

after first test everything looks ok. Thanks again!

Laurynas

On Apr 1, 7:13 pm, Herryanto S. \<rails-mailing-l…@andreas-
