Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.