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
7 before_filter :set_language
9 init_gettext('software')
11 def rescue_action_in_public(exception)
12 @message = exception.message
14 render :template => "error", :layout => false, :status => 404
16 render :template => 'error', :layout => "application", :status => 404
24 lang = request.compatible_language_from(LANGUAGES) || "en"
26 lang = params[:lang][0].gsub(/\-/, '_')
34 @distributions = Rails.cache.fetch('distributions', :expires_in => 120.minutes) do
40 # load available distributions
41 def load_distributions
42 uri = URI.parse("http://#{API_HOST}/distributions")
43 request = Net::HTTP::Get.new(uri.path)
44 logger.debug "Loading distributions from #{uri}"
45 @distributions = Array.new
47 Net::HTTP.start(uri.host, uri.port) do |http|
48 http.read_timeout = 30
49 response = http.request(request)
50 unless( response.kind_of? Net::HTTPSuccess )
51 logger.error "Cannot load distributions: '#{response.code}', message: \n#{response.body}"
53 doc = REXML::Document.new response.body
54 doc.elements.each("distributions/distribution") { |element|
55 dist = [element.elements['name'].text, element.elements['project'].text]
56 @distributions << dist
60 @distributions << ["ALL", 'ALL']
63 logger.error "Error while loading distributions from '#{uri}': " + e.to_s