Sha256: 9bb07aaac938aedaf3d58293a33184f2c49a52b904038fc603b514eee936c99c

Contents?: true

Size: 1.25 KB

Versions: 7

Compression:

Stored size: 1.25 KB

Contents

class GroupsController < InheritedResources::Base
  # Set group founder to current_subject
  # Must do before authorization
  before_filter :set_founder, :only => :new

  load_and_authorize_resource

  respond_to :html, :js

  def index
    @groups = Group.most(params[:most]).
                    alphabetic.
                    letter(params[:letter]).
                    name_search(params[:search]).
                    tagged_with(params[:tag]).
                    page(params[:page]).per(10)

    index! do |format|
      format.html { render :layout => (user_signed_in? ? 'application' : 'frontpage') }
    end
  end

  def show
    show! do |format|
      format.html { render :layout => (user_signed_in? ? 'application' : 'frontpage') }
    end
  end

  def create
    create! do |success, failure|
      success.html {
        self.current_subject = @group
        redirect_to :home
      }
    end
  end

  protected

  # Overwrite resource method to support slug
  # See InheritedResources::BaseHelpers#resource
  def resource
    @group ||= end_of_association_chain.find_by_slug!(params[:id])
  end

  private

  def set_founder
    return unless user_signed_in?

    params[:group]            ||= {}
    params[:group][:_founder] ||= current_subject.slug
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
social_stream-base-0.9.4 app/controllers/groups_controller.rb
social_stream-base-0.9.3 app/controllers/groups_controller.rb
social_stream-base-0.9.2 app/controllers/groups_controller.rb
social_stream-base-0.9.1 app/controllers/groups_controller.rb
social_stream-base-0.9.0 app/controllers/groups_controller.rb
social_stream-base-0.8.2 app/controllers/groups_controller.rb
social_stream-base-0.8.1 app/controllers/groups_controller.rb