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' } %>Vendor | Location |
---|
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!