Class: Muck::SharesController

Inherits:
ApplicationController
  • Object
show all
Defined in:
app/controllers/muck/shares_controller.rb

Instance Method Summary collapse

Instance Method Details

#createObject



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'app/controllers/muck/shares_controller.rb', line 24

def create
  @share = current_user.shares.build(params[:share])
  @share.save!
  # TODO add UI that will let the user share with specific users
  share_to = nil
  attach_to = @share.discover_attach_to rescue nil # try to find an object to attach the activity to ie an entry
  @share.add_share_activity(share_to, attach_to)
  message = t('muck.shares.create_success')
  handle_after_create(true, message)
rescue ActiveRecord::RecordInvalid => ex
  if @share
    errors = @share.errors.full_messages.to_sentence
  else
    errors = ex
  end
  message = t('muck.shares.create_error', :errors => errors)
  handle_after_create(false, message)
end

#destroyObject



43
44
45
46
47
48
49
50
51
52
53
# File 'app/controllers/muck/shares_controller.rb', line 43

def destroy
  @share.destroy
  respond_to do |format|
    format.html do
      flash[:notice] = t('muck.shares.share_removed')
      redirect_back_or_default(current_user)
    end
    format.js { render :template => 'shares/destroy', :layout => false }
    format.json { render :json => { :success => true, :message => t("muck.shares.share_removed"), :share_id => @share.id } }
  end
end

#indexObject



7
8
9
10
11
12
13
# File 'app/controllers/muck/shares_controller.rb', line 7

def index
  @shares = @user.shares.by_newest
  respond_to do |format|
    format.html { render :template => 'shares/index' }
    format.pjs { render :template => 'shares/index', :layout => false }
  end
end

#newObject



15
16
17
18
19
20
21
22
# File 'app/controllers/muck/shares_controller.rb', line 15

def new
  @page_title = t('muck.shares.new_share')
  @share = Share.new(:uri => params[:uri] || params[:u], :title => params[:title] || params[:t], :message => params[:message] || params[:m])
  respond_to do |format|
    format.html { render :template => 'shares/new', :layout => 'popup' }
    format.pjs { render :template => 'shares/new', :layout => false }
  end
end