Class: Storytime::Dashboard::SubscriptionsController

Inherits:
Storytime::DashboardController show all
Defined in:
app/controllers/storytime/dashboard/subscriptions_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#authenticate_user!, #current_user, #setup, #user_signed_in?

Methods included from Concerns::CurrentSite

#current_storytime_site

Methods included from Concerns::ControllerContentFor

#content_for, #content_for?, #view_context

Instance Method Details

#createObject



26
27
28
29
30
31
32
33
34
35
36
# File 'app/controllers/storytime/dashboard/subscriptions_controller.rb', line 26

def create
  @subscription = Storytime::Subscription.new(subscription_params)
  authorize @subscription

  if @subscription.save
    load_subscriptions
    render :index
  else
    render :form, status: 422
  end
end

#destroyObject



54
55
56
57
58
# File 'app/controllers/storytime/dashboard/subscriptions_controller.rb', line 54

def destroy
  authorize @subscription
  @subscription.destroy
  respond_with @subscription
end

#editObject



38
39
40
41
# File 'app/controllers/storytime/dashboard/subscriptions_controller.rb', line 38

def edit
  authorize @subscription
  render :form
end

#indexObject



16
17
18
# File 'app/controllers/storytime/dashboard/subscriptions_controller.rb', line 16

def index
  authorize @subscriptions
end

#newObject



20
21
22
23
24
# File 'app/controllers/storytime/dashboard/subscriptions_controller.rb', line 20

def new
  @subscription = Storytime::Subscription.new
  authorize @subscription
  render :form
end

#unsubscribeObject



60
61
62
63
64
65
66
67
68
# File 'app/controllers/storytime/dashboard/subscriptions_controller.rb', line 60

def unsubscribe
  @subscription = Storytime::Subscription.find_by(token: params[:t])

  if @subscription.nil?
    redirect_to main_app.storytime_path, alert: I18n.t('flash.subscriptions.unsubscribe.not_found')
  else
    @subscription.update(subscribed: false)
  end
end

#updateObject



43
44
45
46
47
48
49
50
51
52
# File 'app/controllers/storytime/dashboard/subscriptions_controller.rb', line 43

def update
  authorize @subscription

  if @subscription.update(subscription_params)
    load_subscriptions
    render :index
  else
    render :form, status: 422
  end
end