Forum: Ruby on Rails Model update/create not saved to params[]

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
006a4831843b48f6102d5d3cf92ae283?d=identicon&s=25 Shilo Ayalon (gte351s)
on 2009-01-20 10:15
I'm trying to build a form to create or update a model using remote
call. When I submit the form, I see that the changes aren't applied. I
started the server with --debugger and noticed the params hash doesn't
receive the updates. My code for update form is this:

# /app/views/vendors/_vendor.html.erb
# This is in the partial b/c there's also an option to render a
# read only view as a table row with vendor_nnn as its id

<tr id="active_vendor">
<% if edit_mode -%>
  <% form_for @vendor, :vendor, { :action => 'update',
                                  :id => @vendor } do |f| -%>
    <%= f.text_field :name %>
    <%= f.text_field :location %>
    <%= link_to_remote 'save', :url => { :action => 'update',
                                         :id => @vendor } %>
  <% end -%>
<% end -%>
</tr>

# vendors_controller.rb

def update
  @vendor = Vendor.find(params[:id])
  if @vendor.update_attributes(params[:vendor])
    flash[:notice] = "Vendor <b>#{@vendor.name}</b> was successfully
updated."
    respond_to do |format|
      format.html { redirect_to vendors_path }
      format.js
    end
  end
end

# update.js.rjs -- this is just to
id = params[:id]

# this puts
page.replace "vendor_#{id}",
             :partial => 'vendor',
             :object => Vendor.find(id),
             :locals => { :edit_mode => false }

page.replace_html 'flasher', params[:vendor] unless
params[:vendor].blank?
page.remove "active_vendor"


When submitting the form it just renders the previous data, without the
changes.
Ef0db53920b243d6758c2f6b1306df0d?d=identicon&s=25 Steve Ross (cwd)
on 2009-01-21 04:45
(Received via mailing list)
You will want to use remote_form_for instead of form_for.

A bit of unasked-for advice:

Write your tests or specs and run them all the time. Make sure
everything works without the ajax. Tail your logs and watch the
actions invoked and parameters passed.

Hope this helps.
This topic is locked and can not be replied to.