Created
December 12, 2008 06:05
-
-
Save patrickberkeley/35031 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| <div class="asset"> | |
| <% if asset.new_record? %> | |
| <% fields_for "page[new_asset_attributes][]", asset do |asset_form| -%> | |
| <p> | |
| <%= asset_form.file_field :file %> | |
| <%= link_to_function "remove", "$(this).up('.asset').remove()" %> | |
| </p> | |
| <% end -%> | |
| <% else %> | |
| <p> | |
| <% fields_for "page[existing_asset_attributes][]", asset do |asset_form| -%> | |
| <%= asset_form.hidden_field(:file) %> | |
| <% end %> | |
| <%= image_tag asset.file.url(:small) %> | |
| <%= link_to_function "remove", "$(this).up('.asset').remove()" %> | |
| </p> | |
| <% end %> | |
| </div> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| wrong number of arguments (1 for 0) | |
| app/models/page.rb:21:in `delete' | |
| app/models/page.rb:21:in `existing_asset_attributes=' | |
| app/models/page.rb:16:in `each' | |
| app/models/page.rb:16:in `existing_asset_attributes=' | |
| app/controllers/pages_controller.rb:76:in `update' | |
| app/controllers/pages_controller.rb:75:in `update' | |
| {"commit"=>"Update", | |
| "_method"=>"put", | |
| "authenticity_token"=>"5d3b9b14bc062c461bdc64eca48e10c8c17c9d48", | |
| "id"=>"11", | |
| "page"=>{"permalink"=>"agaaaaain", | |
| "name"=>"foo", | |
| "existing_asset_attributes"=>{"33"=>{"file"=>"/files/33/original/100_0450.JPG?1228809588"}, | |
| "32"=>{"file"=>"/files/32/original/100_0160.JPG?1228809584"}}, | |
| "content"=>"foo"}} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def existing_asset_attributes=(asset_attributes) | |
| assets.reject(&:new_record?).each do |asset| | |
| attributes = asset_attributes[asset.id.to_s] | |
| if attributes | |
| asset.attributes = attributes | |
| else | |
| asset.delete(asset) | |
| end | |
| end | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment