# Help with link\_to\_remote and RJS

**URL:** <https://www.ruby-forum.com/t/help-with-link-to-remote-and-rjs/157672>\
**Category:** Rails\
**Created:** [January 14, 2009, 11:03am UTC](https://www.ruby-forum.com/t/help-with-link-to-remote-and-rjs/157672 "2009-01-14T11:03:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![gte351s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5f9b8f/32.png) [@gte351s](https://www.ruby-forum.com/u/gte351s)\
**Post date:** [January 14, 2009, 11:03am UTC](https://www.ruby-forum.com/t/help-with-link-to-remote-and-rjs/157672/1 "2009-01-14T11:03:11Z")

</div>

Hi all -

New to rails, I have a page that contains a simple table for vendors,  
with name a location fields. I’m trying to create an ‘add vendor’ link,  
that adds a small to insert a new vendor on the fly. Here’s what I have  
in code:

# app/views/vendors/index.html.erb

# Our Vendors

\<%= link\_to\_remote 'add vendor', :url =\> { :action =\> 'new' } %\> \<%= render :partial =\> 'vendor', :collection =\> @vendors %\> 

| Vendor | Location |
| --- | --- |

# app/views/vendors/\_vendor.html.erb \<% @vendor = vendor %\> \<%= vendor.name %\> \<%= vendor.location %\> # app/views/\_new\_vendor.html.erb \<% form\_for :vendor, :url =\> { :action =\> 'create' } do |f| -%\> \<%= f.text\_field :name, :size =\> 15 %\> \<%= f.text\_field :location, :size =\> 15 %\> \<%= submit\_tag 'save' %\> \<% end -%\> # app/controllers/vendors\_controller.rb class VendorsController \< ApplicationController

def index  
@vendors = Vendor.find(:all, :order =\> ‘name’)  
end

def new  
@vendor = Vendor.new  
respond\_to do |format|  
format.html { render :partial =\> ‘new\_vendor’, :object =\>  
Vendor.new }  
format.js  
end  
end

def create  
@vendor = Vendor.new(params[:vendor])  
end  
end

# app/views/vendors/new.js.rjs

page.insert\_html :after, ‘vendors-headers’, :partial =\> ‘new\_vendor’,  
:object =\> Vendor.new  
I have a couple of issues. The first is that clicking the ‘add vendor’  
does add a table row with the form to the markup, but it doesn’t show on  
the page. I can see the page source adding the rows with the form  
elements (in firebug), but it’s as if the “display:none” is set on them  
(no css is linked to the page, so that isn’t it). I’m thinking it might  
be because I’m not linking the form to the model properly, but I can’t  
see where I might be erring.

The other thing is I’m not sure how to complete the ‘create’ part so  
that the new vendor is added properly to the table via rjs.

Any help will be awesome!

---

<div class="post-metadata">

**Author:** ![gte351s](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/g/5f9b8f/32.png) [@gte351s](https://www.ruby-forum.com/u/gte351s)\
**Post date:** [January 14, 2009, 12:14pm UTC](https://www.ruby-forum.com/t/help-with-link-to-remote-and-rjs/157672/2 "2009-01-14T12:14:57Z")

</div>

On 14 Jan 2009, at 10:03, Shilo A. wrote:

> them  
> (no css is linked to the page, so that isn’t it). I’m thinking it  
> might  
> be because I’m not linking the form to the model properly, but I can’t  
> see where I might be erring.

I don’t think it’s not legal markup. a

 tag may only contain   
tags.

Fred
