-
-
Save mrmemes-eth/977349 to your computer and use it in GitHub Desktop.
Duplicate items when using update_attributes and decent_exposure
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
class AttachedFile < ActiveRecord::Base | |
belongs_to :parent, :polymorphic => true | |
end |
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
class Event < ActiveRecord::Base | |
has_many :attached_files, :as => :parent | |
accepts_nested_attributes_for :attached_files, :allow_destroy => true, :reject_if => proc { |attrs| attrs.all? { |k, v| v.blank? } } | |
end |
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
class Admin::EventsController < ApplicationController | |
respond_to :html | |
expose(:events) { Event.all } | |
expose(:event) | |
def create | |
event.save | |
respond_with(:admin, event) | |
end | |
def update | |
event.update_attributes(params[:event]) | |
respond_with(:admin, event) | |
end | |
end |
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
<% form_for [:admin, event] do |f| %> | |
<%= f.text_field :name %> | |
<%- f.fields_for :attached_files, event.attached_files.build do |a| %> | |
<%= a.text_field :name %> | |
<% end %> | |
<%= f.submit %> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment