Help with link_to_remote and RJS

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!

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