Reputation: 245
I have the following code and would like it so that you can click on "delete" it will check the checkbox. Is there a simple solution for this? I can't figure out how to do it with link_to.
<%= f.fields_for :photos do |photo_fields| %>
<% unless photo_fields.object.new_record? %>
<%= link_to image_tag(photo_fields.object.photo.url(:user_thumbnail)), photo_fields.object.photo.url(:original), class: "fancybox"%>
<%= photo_fields.check_box :_destroy %> <span> delete </span>
<% end %>
<% end %>
Upvotes: 2
Views: 2428
Reputation: 4344
If you make the text part of the label for the checkbox, clicking it should toggle the checkbox. For example, change:
<%= photo_fields.check_box :_destroy %> <span> delete </span>
to:
<label>
<%= photo_fields.check_box :_destroy %>
<span> delete </span>
</label>
Upvotes: 4