My form partial is being used to create new, and also for editing.
<% form_for @deal, :html => { :multipart => true } do |f| %>
<%= f.error_messages %>
<%= f.label :city_id %> <%= f.collection_select :city_id, City.find(:all), :id, :name, { :prompt => 'Select a city' }, {:class => 'foobar'} %>
<%= f.label :title %>
<%= f.text_field :title %>
<%= f.label :description %>
<%= f.text_area :description %>
<%= f.label :price %>
<%= f.text_field :price %>
<%= f.label :value %>
<%= f.text_field :value %>
<%= f.label :discount %>
<%= f.text_field :discount %>
<%= f.label :savings %>
<%= f.text_field :savings %>
<%= f.label :goal %>
<%= f.text_field :goal %>
<%= f.label :countdown %>
<%= f.text_field :countdown %>
<%= f.label :purchased %>
<%= f.text_field :purchased %>
<% f.fields_for :photos do |builder| %>
<%= builder.label :photo, “Photos” %>
<% if [email protected]_record? %>
<%= image_tag :photo.url(:small) %>
<% else %>
<%= builder.file_field :photo %>
<% end %>
<br />
<!--
<%= builder.check_box :_destroy %>
<%= f.label :destroy, "Remove photo" %>
-->
<%= builder.hidden_field :_destroy %>
<%= link_to_function "remove", "remove_fields(this)" %>
</p>
<% end %>
<%= link_to_add_fields "Add photos", f, :photos %>
<% f.fields_for :features do |builder| %>
<%= builder.label :description, “Features” %>
<%= builder.text_area :description, :rows => 3 %>
<!--
<%= builder.check_box :_destroy %>
<%= f.label :destroy, "Remove description" %>
-->
<%= builder.hidden_field :_destroy %>
<%= link_to_function "remove", "remove_fields(this)" %>
</p>
<% end %>
<%= link_to_add_fields "Add feature", f, :features %>
<%= f.submit 'Save' %>
<% end %>Im having trouble with the following lines:
<% if [email protected]_record? %>
<%= image_tag :photo.url(:small) %>
<% else %>
<%= builder.file_field :photo %>
<% end %>
<br />
When I am creating a new deal. The file_field appears appropriately.
But if I am editing a deal with existing photos, I cant get <%=
image_tag :photo.url(:small) %> to show…
All this is inside the <% f.fields_for :photos do |builder| %> loop.
Which is needed for <%= builder.hidden_field :_destroy %> and <%=
link_to_function “remove”, “remove_fields(this)” %>, which are meant
to remove photos when the form is submitted.
How can I get all this to work?