Skip to content

Instantly share code, notes, and snippets.

@jens
Created May 17, 2011 19:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save jens/977180 to your computer and use it in GitHub Desktop.
Save jens/977180 to your computer and use it in GitHub Desktop.
Duplicate items when using update_attributes and decent_exposure
class AttachedFile < ActiveRecord::Base
belongs_to :parent, :polymorphic => true
end
<%= form_for [:admin, event] do |f| %>
<%= f.text_field :name %>
<%= f.fields_for :attached_files do |a| %>
<%= a.text_field :name %>
<% end %>
<%= f.submit %>
<% end %>
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
class Admin::EventsController < ApplicationController
respond_to :html
expose(:events)
expose(:event)
def new
respond_with event
end
def create
event.save
respond_with(:admin, event)
end
def show
respond_with (:admin, event)
end
def edit
respond_with event
end
def update
event.update_attributes(params[:event])
respond_with(:admin, event)
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment