Refactor UserCalloutsController enum check

This commit is contained in:
Matija Čupić 2018-02-05 14:48:28 +01:00
parent a85b85e1d8
commit 5976410be2
No known key found for this signature in database
GPG Key ID: 4BAF84FFACD2E5DE
1 changed files with 3 additions and 7 deletions

View File

@ -1,6 +1,6 @@
class UserCalloutsController < ApplicationController
def create
if check_feature_name && ensure_callout
if ensure_callout.persisted?
respond_to do |format|
format.json { head :ok }
end
@ -13,15 +13,11 @@ class UserCalloutsController < ApplicationController
private
def check_feature_name
UserCallout.feature_names.keys.include?(callout_param)
end
def ensure_callout
current_user.callouts.find_or_create_by(feature_name: callout_param)
current_user.callouts.find_or_create_by(feature_name: UserCallout.feature_names[feature_name])
end
def callout_param
def feature_name
params.require(:feature_name)
end
end