rubyonrailsin

A Ruby and Rails talk

Friday, April 2, 2010


[Rails] please help; form_for passes nil

by rubyonrailsin 0 comments

Tag


Share this post:
Design Float
StumbleUpon
Reddit

I have an update button that doesn't update. Watching the server
during the attempt, I see:

Processing OrvesController#update (for 128.119.60.171 at 2010-04-02
13:13:29) [PUT]
Parameters: {"orf"=>nil, "commit"=>"Update", "id"=>"19544"}

orf is my model I'm trying to update in the database. Why is it nil?

The view for the page with the update button is called edit.html.erb
and contains:

<h1>Editing orf</h1>
<table>
<% form_for @orf do |f| %></td>
<td><%= f.error_messages %>
<td><%= h @orf.locus_tag %></td>
<td><%= f.text_field 'current_annotation', :size => 50 %></td>
<td><%= f.submit "Update" %></td>
<td><%= button_to "Undo last change", :action
=> :undo_last_change, :id => @orf %></td>
<% end %>

orf's attributes locus_tag and current_annotation are being correctly
displayed.

Here's the update method:

def update
@orf = Orf.find(params[:id])
if @orf.update_attributes(params[:orf])
flash[:notice] = 'Orf was successfully updated.'
redirect_to orf_path
else
flash[:notice] = 'Update failed.'
redirect_to orf_path
end
end

routes.rb contains the line:
map.resources :orves

No error message appears in the web browser. The update just doesn't
change anything.

I'm running Rails 2.3.0.

Any idea what I'm doing wrong?

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

No comments:

Post a Comment

Subscribe feeds via e-mail

Blog Archive