Sha256: 3c89706364fdf3cb7e38d35b6827a5ee23b22b6998cc5bb0a14a84fbedd06d66

Contents?: true

Size: 1.64 KB

Versions: 6

Compression:

Stored size: 1.64 KB

Contents

module Saucy
  module ProjectsController
    extend ActiveSupport::Concern

    included do
      before_filter :authorize_member,      :only   => :show
      before_filter :authorize_admin,       :except => [:show]
      before_filter :ensure_active_account, :only   => [:show, :destroy, :index]
      before_filter :ensure_account_within_projects_limit, :only => [:new, :create]
      layout Saucy::Layouts.to_proc
    end

    module InstanceMethods
      def new
        @project = current_account.projects.build_with_default_permissions
      end

      def create
        @project = current_account.projects.build(params[:project])
        if @project.save
          flash[:notice] = "Project successfully created"
          redirect_to project_url(@project)
        else
          render :action => :new
        end
      end

      def edit
        current_project
      end

      def update
        if current_project.update_attributes params[:project]
          flash[:success] = 'Project was updated.'
          redirect_to account_projects_url(current_account)
        else
          render :action => :edit
        end
      end

      def show
        current_project
      end

      def destroy
        current_project.destroy
        flash[:success] = "Project has been deleted"
        redirect_to account_projects_url(current_project.account)
      end

      def index
        @projects = current_account.projects
      end

      private

      def current_project
        @project ||= ::Project.find_by_keyword!(params[:id])
      end

      def ensure_account_within_projects_limit
        ensure_account_within_limit("projects")
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
saucy-0.4.1 lib/saucy/projects_controller.rb
saucy-0.3.4.1 lib/saucy/projects_controller.rb
saucy-0.4.0 lib/saucy/projects_controller.rb
saucy-0.3.4 lib/saucy/projects_controller.rb
saucy-0.3.3 lib/saucy/projects_controller.rb
saucy-0.3.2 lib/saucy/projects_controller.rb