Created
May 17, 2011 19:25
-
-
Save jens/977180 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
<%= 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 %> |
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) | |
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