I have the following form for photo_album which uses the nested forms
feature of the Rails in saving the photos while updating the
photo_album. And having trouble with the selection of radio button
value. I want only one of the photos be able to select as the album
cover, but due to the way rails produces form element ids and names, I
am able to select all of the photos as album covers. Is there any
workaround?
<% form_for @photo_album do |f| %>
<%= f.error_messages %>
<% @photo_album.photos.each do |photo| %>
<% f.fields_for :photos, photo do |photo_fields| %>
<%= image_tag url_for_image_column(photo, “data”, :thumb) %>
<%= photo_fields.label :title %>
<%= photo_fields.text_field :title %>
<%= photo_fields.label :body %>
<%= photo_fields.text_area :body %>
<%= photo_fields.radio_button :cover, “1” %>
<%= photo_fields.label :cover, ‘Album Cover’, :class => ‘option’
%>
<%= photo_fields.check_box :_delete %>
<%= photo_fields.label :_delete, ‘Delete’, :class => ‘option’ %>
<% end %>
<% end %>
<%= f.submit @photo_album.new_record? ? 'Create' : 'Update' %>
<% end %>And following is the html produced by rails (which is part of the
problem) for radio buttons:
Album Cover Delete