To be true, this question ha another origin: I’m setting up an update
page. This page renders a partial of the form, used both for the create
and update pages. I thought that passing an id to the form, the view
would show me the field already filled with the existing data to be
edited. But this does not happens. And I thought the reason was in the
object I’m (maybe not) passing…
The link to the main view:
<% @entries.each do |e| -%>
<% @e=e %>
<tr class="<%= cycle(“even”, “odd”) -%>">
<%= e.entry_date -%> |
<%= e.title -%> |
<%= e.content -%> |
<%= check_box( ‘e[]’,‘visible’,{},true,false)
-%> |
<%= link_to ‘Destroy’,
{ :action => ‘delete_entry’, :id => e.id },
{ :confirm => ‘Would?’ }
-%> |
<%= link_to ‘Modify’, { :action => ‘editEntry’, :id
=> e.id } -%> |
<% end -%>
The main view:
<% form_for :entry, :url => { :action => :update_entry, :id => @entry }
do |f| %>
<%= render :partial => "form", :locals => { :f => f } %>
<% end %>
the form partial (that does not show the fields filled with existing
data):
Entry Date
<%= f.date_select :entry_date, :start_year => 2007 %>
Title
<%= f.text_field :title %>
Content
<%= f.text_area :content %>
The controller (incomplete):
def edit_entry
@entry = Entry.find(params[:id])
end
def update_entry
@entry = Entry.find(params[:id])
if @entry.update_attributes(params[:entry])
redirect_to :action => ‘list’
else
render :action => ‘editEntry’
end
end
Do you maybe know why?