Form_remote_tag and RJS

I wrote some code for adding a category to a list of categories on a
page, complete with some rjs effects. The code saves the category
alright but does not execute any js. I have to refresh to see any
changes. Here is what I have been using:

VIEW: list.html.erb

    <%= render :partial => 'category', :collection => @categories %>

<% form_remote_tag :url => {:action => ‘new’},
:html => {:id => ‘category_form’} do %>
Name: <%= text_field ‘category’, ‘name’ %>
<%= submit_tag “Add” %>
<% end %>

CONTROLLER: category_controller.rb

def new
@category =[:category])
respond_to do |format|
render :partial => ‘category’, :object => @category

def list
@categories = Category.find(:all)

RJS: new.js.erb

page.insert_html :bottom, :category_list, :partial => ‘category’,
:object => @category
page.visual_effect :highlight, “category_#{}”

Has anyone else run into this issue or have any ideas about where I am
going wrong?

You can use the :collections parameter to render the list. I don’t
see a need for new.js.erb.

Use the :update=> parameter for the form tag to get the browser to
refresh a section of the screen. Put your partial inside a

pass the id of the
to the update parameter.

You can do the highlights etc. as parameters to the form_remote_tag.
Look at the documentation for form_remote_tag.

On Apr 6, 4:24 am, Jack K. [email protected]

On 6 Apr 2008, at 00:24, Jack K. wrote:


This can’t be exactly what’s in your controller because it’s
syntatically incorrect. But I’d guess that your new.js.erb file is
never exececuted, since you’re telling it to render the partial
instead. On top of that it should be called new.js.rjs, not new.js.erb


I finally got it working. Many thanks to Fred and Mukund.
I changed two things: Firstly instead of putting the div id into an
unordered list I made a separate div tag. Secondly I got rid of the
render partial line in the controller.