abstract finding of object
This commit is contained in:
parent
051bbc9485
commit
ac02238d62
@ -5,6 +5,18 @@ class ApplicationController < ActionController::Base
|
|||||||
before_action :authenticate_user_from_token!, except: [:publish]
|
before_action :authenticate_user_from_token!, except: [:publish]
|
||||||
before_action :authenticate_user!, except: [:publish] #unless Rails.env.test?
|
before_action :authenticate_user!, except: [:publish] #unless Rails.env.test?
|
||||||
|
|
||||||
|
|
||||||
|
def set_by_options(name, field)
|
||||||
|
what = params[field]
|
||||||
|
model = name.to_s.classify.constantize
|
||||||
|
if params[name]
|
||||||
|
object = model.find_by(field => params[name][field]) || not_found
|
||||||
|
else
|
||||||
|
object = model.find_by(field=>what) || not_found
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
|
|
||||||
|
@ -58,12 +58,7 @@ class CampaignsController < ApplicationController
|
|||||||
|
|
||||||
private
|
private
|
||||||
def set_campaign
|
def set_campaign
|
||||||
listingcode = params[:listingcode]
|
@campaign = set_by_options(:campaign, :listingcode)
|
||||||
if params[:campaign]
|
|
||||||
@campaign = Campaign.find_by_listingcode(params[:campaign][:listingcode]) || not_found
|
|
||||||
else
|
|
||||||
@campaign = Campaign.find_by_listingcode(listingcode) || not_found
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
def campaign_params
|
def campaign_params
|
||||||
|
@ -17,12 +17,7 @@ class VideolistingsController < ApplicationController
|
|||||||
private
|
private
|
||||||
# Use callbacks to share common setup or constraints between actions.
|
# Use callbacks to share common setup or constraints between actions.
|
||||||
def set_videolisting
|
def set_videolisting
|
||||||
videocode = params[:videocode]
|
@videolisting = set_by_options(:videolisting, :videocode)
|
||||||
if params[:videolisting]
|
|
||||||
@videolisting = Videolisting.find_by_videocode(params[:videolisting][:videocode]) || not_found
|
|
||||||
else
|
|
||||||
@videolisting = Videolisting.find_by_videocode(videocode) || not_found
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
# Only allow a trusted parameter "white list" through.
|
# Only allow a trusted parameter "white list" through.
|
||||||
|
Loading…
Reference in New Issue
Block a user