Sha256: 594fa74dd5abba01fbf3ed5ae777682a05730c06072b9b02d5e497ea3905330a

Contents?: true

Size: 1.5 KB

Versions: 1

Compression:

Stored size: 1.5 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', :layout => false
        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.4 lib/double_auth_engine/controllers/users_controller_mixin.rb