Rails 3 & Ajax

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

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

http://railscasts.com/episodes/196-nested-model-form-part-1

http://railscasts.com/episodes/196-nested-model-form-part-2

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