Answer the question
In order to leave comments, you need to log in
Rubies, help me out! How to refactor the following method?
Here is the code:
def generate_link(campaign_id)
source = self.find(campaign_id).source
params = {}
if source.sub1 != ''
params[:sub1] = @source.sub1
end
if source.sub2 != ''
params[:sub2] = @source.sub2
end
if source.sub3 != ''
params[:sub3] = @source.sub3
end
if source.sub4 != ''
params[:sub4] = @source.sub4
end
if source.sub5 != ''
params[:sub5] = @source.sub5
end
if source.sub6 != ''
params[:sub6] = @source.sub6
end
@link = Settings.tds.url + campaign_id + (params.present? ? ('?' + params.to_query) : '')
end
subs = [sub1, sub2, sub3, sub4, sub5, sub6]
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question