I have a program that stores details of sauces.
Basically when I get to the edit form, im doing everything im supposed to be doing, the id is passed through successfully, however all the form fields stay empty rather than having the values that are already in the database displayed in them.
In my controller :
def edit
@sauce = Sauce.find(params[:id])
@pagetitle = "Edit #{@sauce.name} Sauce"
end
def update
# Find object using form parameters
@sauce = Sauce.find(params[:id])
# Update the object
if @sauce.update_attributes(params[:page])
# If update succeeds, redirect to the list action
flash[:notice] = "Sauce updated."
redirect_to(:action => 'list')
else
# If save fails, redisplay the form so user can fix problems
render('edit')
end
The form Partial :
<%= error_messages_for(@sauce) %>
<table summary="Sauces Form Fields">
<tr>
<th><%= f.label(:name,"Sauce Name") %></th>
<td><%= f.text_field(:name) %></td>
</tr>
<tr>
<th><%= f.label(:description, "Description") %></th>
<td><%= f.text_area(:description, :size => '40x5') %></td>
</tr>
<tr>
<th><%= f.label(:heat_level, "Heat Level") %></th>
<td><%= f.select(:heat_level,{ 1 => "1", 2 => "2", 3 => "3", 4 => "4", 5 => "5"}) %></td>
</tr>
<tr>
<th><%= f.label(:pic_url, "Picture URL") %></th>
<td><%= f.text_field(:pic_url) %></td>
</tr>
<tr>
<th><%= f.label(:title_colour, "Title Colour") %></th>
<td><%= f.text_field(:title_colour) %></td>
</tr>
<tr>
<th><%= f.label(:description_colour, "Desc Colour") %></th>
<td><%= f.text_field(:description_colour) %></td>
</tr>
</table>
my edit.html.erb
<%= form_for(:subject, :url => {:action => 'update', :id => @sauce.id}) do |f| %>
<%= render(:partial => "form", :locals => {:f => f}) %>
<%= submit_tag("Update Subject") %>
<% end %>
Where am I going wrong?
The error is
form_for(:subject). If you want Rails to correctly fill in the form, you need to use the same symbol as the instance variable has, or just the instance variable. Try this instead: