1 # Filters added to this controller apply to all controllers in the application.
2 # Likewise, all the methods added will be available for all controllers.
4 class ApplicationController < ActionController::Base
6 before_filter :set_distributions
8 init_gettext('software')
10 def rescue_action_in_public(exception)
11 @message = exception.message
13 render :template => "error", :layout => false, :status => 404
15 render :template => 'error', :layout => "application", :status => 404
22 @distributions = Rails.cache.fetch('distributions', :expires_in => 120.minutes) do
28 # load available distributions
29 def load_distributions
30 uri = URI.parse("http://#{API_HOST}/distributions")
31 request = Net::HTTP::Get.new(uri.path)
32 logger.debug "Loading distributions from #{uri}"
33 @distributions = Array.new
35 Net::HTTP.start(uri.host, uri.port) do |http|
37 response = http.request(request)
38 unless( response.kind_of? Net::HTTPSuccess )
39 logger.error "Cannot load distributions: '#{response.code}', message: \n#{response.body}"
41 doc = REXML::Document.new response.body
42 doc.elements.each("distributions/distribution") { |element|
43 dist = [element.elements['name'].text, element.elements['project'].text]
44 @distributions << dist
49 logger.error "Error while loading distributions from '#{uri}': " + e.to_s
51 @distributions << ["ALL", 'ALL']