Rails 2.0.2 + RJS

Elaborate on “do not work”

Do they get called and raise an error do they not get called at all? Is the page loading at all? Are you using Firefox? Do you have Firebug? What is Firebug telling you about the AJAX request? Do you like cheese on toast? What’s the square root of 24… the questions are endless.

Have you found a solution to this. I am having the same problem.

I do something like this:

            page.replace "student_#{@student.id}", :partial => "show", :locals => {:rendition => @rendition}             page.visual_effect :highlight, "student_#{@student.id}", {:endcolor => "'#EAE8D5'", :endcolor => "'#EAE8D5'"}

If I comment out the 2nd line the replace works fine. The highlight seems to kill any kind of javascript running.

change    create.js to    create.js.rjs

I just did a refresher on rjs for rails 2

I wrote up what I changes. I was using Peepcode rjs screencast my post http://johnivanoff.blogspot.com/#2317945271487058293

peepcode http://peepcode.com/products/rjs-templates

HTH john i

Do you have a create.rhtml file as well? If you move it to create.html.erb, your problem will go away.

I think you should have a create.html.erb file incase the user does not have javascript turned on.

In the controller you have the respond_to

respond_to do |format|    format.js #create.js.rjs    format.html #create.html.erb end

or a more detailed version . . .

   respond_to do |format|       if @task.save         format.html do           flash[:notice] = 'Task was successfully created.'           redirect_to{ (@task)         end         format.js       else         format.html { render :action => "new" }         format.js { render :template => "shared/error.js.rjs" }       end     end

john i

For my Highlighting I am using this code

(in the js.rjs file) page.insert_html :bottom, 'tasks', :partial => @task # adds new task into the partial page['task_form'].reset # resets the form page.visual_effect :highlight, "task_#{@task.id}", # highlights the just added div that has the new task                     :startcolor => '#336699'

I use a partial in my index.html.erb view. <div id="tasks">   <%= render :partial => @tasks %> </div>

_task.html.erb file <% div_for task do %>   <%= h(task.name) %> <% end %>

the div_for task do gives the div an id = to task_1 (or what ever the id of the task is.) Example: I have one task that has an id of 1 I add a new task. It gets an id of 2

In the rjs 1) It adds a new div, with an id = task_2, into the div on the index view that has the id of "tasks". 2) It clears the form with the reset. 3) highlight the task_2

my form view

<% remote_form_for(:task, :url => tasks_path, :html => {:id => "task_form"}) do |f| %>   <p>     <b>Name</b><br />     <%= f.text_field :name %>   </p>   <p>     <b>Value</b><br />     <%= f.text_field :value %>   </p>   <p>     <%= f.submit "Create" %>   </p> <% end %>


I'm having the same problems, except I can't even seem to get any of the effects to work or calls like 'page.call :my_function'. I've got an index.html.erb file, and an index.hs.rjs file. The js.rjs file just has:

page.visual_effect :highlight, "my_div"

and my controller has:

respond_to do |format|     format.js { render :template => "index.js.rjs" } end

But whatever I do I can't seem to make this work. It always complains with the try/catch error that has something like "alert('RJS error:\n \n' + e.toString())". I've also tried changing the page.visual_effect to a page.call, and I cant make this work either. Any ideas?

Why the hell did this change in rails 2.0 anyway, what was wrong with the way it worked, where you could just do:

render :update do |page|    page.call :alert, "Im js" end

And not have to worry about creating a stupid js.rjs file.