Ad.unverified_ads.last
The work of loading the last unverified ad should not be performed
directly by the view. It’s not the views responsibility. Besides that,
this line is a direct violation if the Law of Demeter (LoD). While, I
only partially support the concept of LoD, doing this in the view is
really crossing that line.
I don’t understand the purpose of these two methods. They find an ad and
do nothing else. Seems rather pointless to me. I could be missing
something here.
If you just need to have the same ad loaded in more than one action
method
then use a before filter to load it.
before_filter :load_ad
private
def load_ad @ad = Ad.find(params[:id])
end
See
for more on controller filters.
def fast_verify @ad = Ad.find(params[:id]) @ad.verify!
if Ad.unverified_ads.size == 0
redirect_to verifications_path
else
redirect_to
fast_verify_info_verification_path(Ad.unverified_ads.last)
end
end
def verify @ad = Ad.find(params[:id]) @ad.verify!
if params[:fast] == true
redirect_to Ad.unverified_ads.last
else
redirect_to verifications_path
end
end
Again I see Ad.unverified_ads.last. If this is important enough to keep
restating multiple times then it’s important enough for your Ad model to
know how to do it.
Ad.last_unverified (This helps resolve the LoD issue).
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.