Sha256: 57534af6e7abc594d36556902f5ba4673d21f804d3684215a6b530d301de459e
Contents?: true
Size: 1.73 KB
Versions: 22
Compression:
Stored size: 1.73 KB
Contents
class AdminAssistant module Request class Update < Base def call saving = Update::Saving.new( model_class.find(@controller.params[:id]), @controller ) if saving.record_and_associations_valid? saving.save if @controller.params[:from] render_response_to_ajax_toggle saving.record else saving.redirect_after_save end else render_single_form saving.record end end def render_response_to_ajax_toggle(record) @controller.params[:from] =~ /#{model_class.name.underscore}_\d+_(.*)/ field_name = $1 index = AdminAssistant::Index.new @admin_assistant erb = <<-ERB <%= index.view(self).columns.detect { |c| c.name == field_name }. ajax_toggle_inner_html(record) %> ERB @controller.send( :render, :inline => erb, :locals => { :index => index, :field_name => field_name, :record => record } ) end class Saving < Request::AbstractSaving def prepare_record_to_receive_invalid_association_assignments params_for_save.errors.each_attribute do |attr| @record.instance_eval <<-EVAL @attempted_attributes ||= {} def #{attr}=(ary) @attempted_attributes[#{attr.inspect}] = ary end def #{attr}; @attempted_attributes[#{attr.inspect}]; end EVAL end end def save if @controller.respond_to?(:before_update) @controller.send(:before_update, @record) end super end end end end end
Version data entries
22 entries across 22 versions & 1 rubygems