Sha256: cd6f5d4ea3d63e78fafabd3ce4c153bf672fecbb2792ce5f54e36e3450f776a5
Contents?: true
Size: 1.09 KB
Versions: 9
Compression:
Stored size: 1.09 KB
Contents
module ImperaviRails module ControllerMethods extend ActiveSupport::Concern module ClassMethods # TODO Add functionality for non-polymorphic models def bind_imperavi_images_to(name, options = {}) raise ArgumentError, "You should specify :with option" unless options[:with] unless options.has_key?(:only) || options.has_key?(:except) options[:only] = [:create, :update] end klass = options[:with] options[:with] = options[:with].to_s.tableize before_filter options do if params[name.to_sym]["#{options[:with]}_attributes"].try(:[], "#{options[:as]}_id") @_imperavi_images_attributes = params[name.to_sym]["#{options[:with]}_attributes"] params[name.to_sym].delete("#{options[:with]}_attributes") end end after_filter options do if @_imperavi_images_attributes klass_instance = klass.find(@_imperavi_images_attributes[:id]) klass_instance.update_attributes(@_imperavi_images_attributes) end end end end end end
Version data entries
9 entries across 9 versions & 1 rubygems