Commit 5976410b authored by Matija Čupić's avatar Matija Čupić

Refactor UserCalloutsController enum check

parent a85b85e1
class UserCalloutsController < ApplicationController class UserCalloutsController < ApplicationController
def create def create
if check_feature_name && ensure_callout if ensure_callout.persisted?
respond_to do |format| respond_to do |format|
format.json { head :ok } format.json { head :ok }
end end
...@@ -13,15 +13,11 @@ class UserCalloutsController < ApplicationController ...@@ -13,15 +13,11 @@ class UserCalloutsController < ApplicationController
private private
def check_feature_name
UserCallout.feature_names.keys.include?(callout_param)
end
def ensure_callout 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 end
def callout_param def feature_name
params.require(:feature_name) params.require(:feature_name)
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment