Class: SubscriptionsController
Instance Method Summary
collapse
#dashboard, #keyboard_tools, #upload
Instance Method Details
#create ⇒ Object
11
12
13
14
15
16
17
18
19
|
# File 'app/controllers/subscriptions_controller.rb', line 11
def create
@subscription = Subscription.new sub_params.merge(user: current_user)
if @subscription.save
flash[:success] = 'Your subscription was saved successfully.'
redirect_to params[:return_to].presence || root_path
else
render :error, status: :internal_server_error
end
end
|
#destroy ⇒ Object
39
40
41
42
43
44
45
46
47
48
49
50
51
|
# File 'app/controllers/subscriptions_controller.rb', line 39
def destroy
@subscription = Subscription.find params[:id]
if current_user.is_admin || current_user.id == @subscription.user_id
if @subscription.destroy
render json: { status: 'success' }
else
render json: { status: 'failed' }, status: :internal_server_error
end
else
render json: { status: 'failed', message: 'You do not have permission to remove this subscription.' },
status: :forbidden
end
end
|
#enable ⇒ Object
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'app/controllers/subscriptions_controller.rb', line 25
def enable
@subscription = Subscription.find params[:id]
if current_user.is_admin || current_user.id == @subscription.user_id
if @subscription.update(enabled: params[:enabled] || false)
render json: { status: 'success', subscription: @subscription }
else
render json: { status: 'failed' }, status: :internal_server_error
end
else
render json: { status: 'failed', message: 'You do not have permission to update this subscription.' },
status: :forbidden
end
end
|
#index ⇒ Object
21
22
23
|
# File 'app/controllers/subscriptions_controller.rb', line 21
def index
@subscriptions = current_user.subscriptions
end
|
#new ⇒ Object
6
7
8
9
|
# File 'app/controllers/subscriptions_controller.rb', line 6
def new
@phrasing = phrase_for params[:type]
@subscription = Subscription.new
end
|