# Form\_remote\_tag and RJS

**URL:** <https://www.ruby-forum.com/t/form-remote-tag-and-rjs/133982>\
**Category:** Rails\
**Created:** [April 6, 2008, 1:24am UTC](https://www.ruby-forum.com/t/form-remote-tag-and-rjs/133982 "2008-04-06T01:24:16Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![postmodernist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bb73d2/32.png) [@postmodernist](https://www.ruby-forum.com/u/postmodernist)\
**Post date:** [April 6, 2008, 1:24am UTC](https://www.ruby-forum.com/t/form-remote-tag-and-rjs/133982/1 "2008-04-06T01:24:16Z")

</div>

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.new(params[:category])  
respond\_to do |format|  
if @category.save  
format.js  
render :partial =\> ‘category’, :object =\> @category  
end

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

RJS: new.js.erb

page.insert\_html :bottom, :category\_list, :partial =\> ‘category’,  
:object =\> @category  
page.visual\_effect :highlight, “category\_#{category.id}”  
page[:category\_form].reset

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

---

<div class="post-metadata">

**Author:** ![postmodernist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bb73d2/32.png) [@postmodernist](https://www.ruby-forum.com/u/postmodernist)\
**Post date:** [April 6, 2008, 3:02pm UTC](https://www.ruby-forum.com/t/form-remote-tag-and-rjs/133982/2 "2008-04-06T15:02:21Z")

</div>

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

 and  
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. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![postmodernist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bb73d2/32.png) [@postmodernist](https://www.ruby-forum.com/u/postmodernist)\
**Post date:** [April 6, 2008, 3:56pm UTC](https://www.ruby-forum.com/t/form-remote-tag-and-rjs/133982/3 "2008-04-06T15:56:26Z")

</div>

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

> end

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

Fred

---

<div class="post-metadata">

**Author:** ![postmodernist](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/p/bb73d2/32.png) [@postmodernist](https://www.ruby-forum.com/u/postmodernist)\
**Post date:** [April 6, 2008, 6:49pm UTC](https://www.ruby-forum.com/t/form-remote-tag-and-rjs/133982/4 "2008-04-06T18:49:22Z")

</div>

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.
