Sha256: 044483d387e2651ecc6d0c7fd4ba64de5134d80c6007d3c7dee06aa90e5b6261

Contents?: true

Size: 1.48 KB

Versions: 1

Compression:

Stored size: 1.48 KB

Contents

module DoubleAuthEngine
  module UsersControllerMixin
    def self.included(base)
      base.class_eval do
        skip_before_filter :require_user, :only => [:new, :create]
        filter_access_to [:edit, :update], :attribute_check => true
        respond_to :html, :json, :js
      end
      base.send :include, InstanceMethods
    end

    module InstanceMethods
      def index
        @users = User.all
        respond_with(@users)
      end

      def show
        @user = User.find(params[:id])
        respond_with @user
      end

      def new
        @user = User.new
        respond_with @user do |format|
          format.html { render :layout => false }
        end
      end

      def create
        @user = User.new(params[:user])
        if @user.save
          flash[:notice] = 'User successfully created'
          respond_with(@user)
        else
          render :action => 'new'
        end
      end

      def edit
        @user = User.find(params[:id])
        respond_with(@user)
      end

      def update
        @user = User.find(params[:id])
        if @user.update_attributes(params[:user])
          flash[:notice] = 'User successfully updated'
          respond_with(@user)
        else
          render :action => 'edit'
        end
      end

      def destroy
        @user = User.find(params[:id])
        @user.destroy
        respond_to do |format|
          format.html { redirect_to(users_url) }
          format.xml { head :ok }
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
double_auth_engine-0.0.2 lib/double_auth_engine/controllers/users_controller_mixin.rb