lib/concerns/yearly_controller.rb
# If any user tries to access a resource while using the wrong
# year's "site", we don't want them to see the resource because
# that could be very misleading.  However, this is unlikely to
# happen. Barring a badly generated URL, the user would have to
# edit the URL manually, changing the year or the resource id.
If any user tries to access a resource while using the wrong
year's "site", we don't want them to see the resource because
that could be very misleading.  However, this is unlikely to
happen. Barring a badly generated URL, the user would have to
edit the URL manually, changing the year or the resource id.
If any user tries to access a resource while using the wrong year ' s " site " we don ' t want them to see the resource because that could be very misleading . However this is unlikely to happen . Barring a badly generated URL the user would have to edit the URL manually changing the year or the resource id .
def ensure_rsrc_year_matches_route_year
    return if params[:id].blank?
    check_that_year_is_present
    model_class ||= controller_name.classify.constantize
    resource = model_class.find(params[:id])
    if resource.year != @year.year
      raise ActiveRecord::RecordNotFound, \
        "Resource year (#{resource.year}) does not match route year (#{@year.year})"
    end
  end
def ensure_rsrc_year_matches_route_year return if params [ :id ] . blank? check_that_year_is_present model_class ||= controller_name . classify . constantize resource = model_class . find ( params [ :id ] ) if resource . year != @year . year raise ActiveRecord :: RecordNotFound , "Resource year (#{resource.year}) does not match route year (#{@year.year})" end end
If any user tries to access a resource while using the wrong
year's "site", we don't want them to see the resource because
that could be very misleading.
If any user tries to access a resource while using the wrong year ' s " site " we don ' t want them to see the resource because that could be very misleading .
# If there's no :id parameter, then skip this validation. # Try to load the resource by id.  This can throw # RecordNotFound, but that would happen later anyway # when cancan (or whatever) loads the resource. # If we find the resource and it doesn't belong to the year # in the route, then raise RecordNotFound which should get # rescued as a 404 in production.