# Rails 3 & Ajax

**URL:** <https://www.ruby-forum.com/t/rails-3-ajax/195101>\
**Category:** Rails\
**Created:** [September 16, 2010, 8:56pm UTC](https://www.ruby-forum.com/t/rails-3-ajax/195101 "2010-09-16T20:56:45Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![crashbangboom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9e8a1a/32.png) [@crashbangboom](https://www.ruby-forum.com/u/crashbangboom)\
**Post date:** [September 16, 2010, 8:56pm UTC](https://www.ruby-forum.com/t/rails-3-ajax/195101/1 "2010-09-16T20:56:45Z")

</div>

Hi…

I’m using rails 3.0…

I have, among others, a controller/model for both provers and  
certifications. I’m rendering a partial list of certifications in a

\<div id='certs\> in the views/provers/show file. I'm also rendering a partial to allow the insertion of a new certification in the same file.

Problem 1:  
I want to use Ajax to refresh the certificaton partial and clear the  
“new certification” fields when a new certification is added.

I have a “create.js.rjs” file that lives in the /views/certifications  
directory and gets called from the “create” method in /controller/  
certifications. Here is the contents of that file:

page.replace\_html(‘certs’, render(’/provers/certs’)) \<-- probably  
wrong…!

No matter how I configure the .rjs file it does not work and the  
problem appears to be that because it is not in the /views/provers  
directory it doesn’t know what to do.

What am I doing wrong…?

Problem 2:  
With the insertion of a new certification I want to update a field in  
the “provers” table of the database. With that in mind, I have the  
“create” method in the certifications controller setup as follows:  
@prover = Prover.find(params[:id =\> @certification.prover\_id])  
I want to set the associated field “cal\_flag” in the table to false  
@prover.cal\_flag = false

When I run this I get a can’t find with id = nil error…(obviously  
not finding the prover with the foreign key “prover\_id”)

Thanks in advance for any/all help…!

Dave

---

<div class="post-metadata">

**Author:** ![crashbangboom](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/9e8a1a/32.png) [@crashbangboom](https://www.ruby-forum.com/u/crashbangboom)\
**Post date:** [September 17, 2010, 2:25am UTC](https://www.ruby-forum.com/t/rails-3-ajax/195101/2 "2010-09-17T02:25:42Z")

</div>

Thats all easy but first, is a little different in rails 3 than in the  
next  
example

here , is not exactly what you want but it will get you started

> **[\#196 Nested Model Form Part 1 - RailsCasts](http://railscasts.com/episodes/196-nested-model-form-part-1)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

> **[\#196 Nested Model Form Part 1 - RailsCasts](http://railscasts.com/episodes/196-nested-model-form-part-1)**
>
> Short Ruby on Rails screencasts containing tips, tricks and tutorials. Great for both novice and experienced web developers.

by the way, i bet you are doing

respond\_to do |format|  
format.html {redirect\_to whatever}  
format.js \<==== you are leaving  
this  
blank  
end

when you dont pass a block to format.js it will call a js file with the  
same name as the action, but you can make it call  
another action like this

respond\_to do |format|  
format.html {redirect\_to whatever}  
format.js { render :action =\> “success” } \<==== calls  
success.js.erb  
in the same view folder  
end

also this

page.replace\_html(‘certs’, render(‘/provers/certs’))

should be this

page.replace\_html(‘certs’, render :partial=\> “provers/certs”)

and this here

@prover = Prover.find(params[:id =\> @certification.prover\_id])

when did you fill the @certification instance, i think i should be empty  
or  
nil in this case
