Sha256: 51a2338d1870dadaba7871010360ad31e7d832373c0b469c7d8764d646d266b9

Contents?: true

Size: 1.96 KB

Versions: 3

Compression:

Stored size: 1.96 KB

Contents

module ActiveScaffold::Actions
  module Clone
    def self.included(base)
      base.before_filter :clone_authorized_filter, :only => :clone
    end
    
    def clone
      old_record = find_if_allowed(params[:id], :read)
      @record = old_record.send(active_scaffold_config.clone.method)
      self.successful = @record.persisted?
      respond_to_action(:clone)
    end
    
    protected
    def clone_authorized?
      authorized_for?(:crud_type => :create, :action => :clone)
    end
    
    def clone_respond_to_html
      if successful?
        flash[:info] = as_(:created_model, :model => @record.to_label)
        if action = active_scaffold_config.clone.action_after_clone
          redirect_to params_for(:action => action, :id => @record.id)
        else
          return_to_main
        end
      else
        return_to_main
      end
    end
    
    def clone_respond_to_js
      render :action => 'clone'
    end

    def clone_respond_to_xml
      render :xml => response_object.to_xml(:only => active_scaffold_config.create.columns.names), :content_type => Mime::XML, :status => response_status, :location => response_location
    end

    def clone_respond_to_json
      render :text => response_object.to_json(:only => active_scaffold_config.create.columns.names), :content_type => Mime::JSON, :status => response_status, :location => response_location
    end

    def clone_respond_to_yaml
      render :text => Hash.from_xml(response_object.to_xml(:only => active_scaffold_config.create.columns.names)).to_yaml, :content_type => Mime::YAML, :status => response_status, :location => response_location
    end
    
    private
    def clone_authorized_filter
      link = active_scaffold_config.clone.link || active_scaffold_config.clone.class.link
      raise ActiveScaffold::ActionNotAllowed unless self.send(link.security_method)
    end
    def clone_formats
      (default_formats + active_scaffold_config.formats + active_scaffold_config.clone.formats).uniq
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
active_scaffold_duplicate-1.0.2 lib/active_scaffold/actions/clone.rb~
active_scaffold_duplicate-1.0.1 lib/active_scaffold/actions/clone.rb~
active_scaffold_duplicate-1.0.0 lib/active_scaffold/actions/clone.rb~