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
8 helper :all # include all helpers, all the time
10 init_gettext('software')
12 def rescue_action_in_public(exception)
13 @message = exception.message
15 render :template => "error", :layout => false, :status => 400
17 render :template => 'error', :layout => "application", :status => 400
25 lang = request.compatible_language_from(LANGUAGES) || "en"
27 lang = params[:lang][0].gsub(/\-/, '_')
35 @distributions = Rails.cache.fetch('distributions', :expires_in => 120.minutes) do
41 # load available distributions
42 def load_distributions
43 uri = URI.parse("http://#{API_HOST}/distributions")
44 request = Net::HTTP::Get.new(uri.path)
45 logger.debug "Loading distributions from #{uri}"
46 @distributions = Array.new
48 Net::HTTP.start(uri.host, uri.port) do |http|
49 http.read_timeout = 30
50 response = http.request(request)
51 unless( response.kind_of? Net::HTTPSuccess )
52 logger.error "Cannot load distributions: '#{response.code}', message: \n#{response.body}"
54 doc = REXML::Document.new response.body
55 doc.elements.each("distributions/distribution") { |element|
56 dist = [element.elements['name'].text, element.elements['project'].text]
57 @distributions << dist
61 @distributions << ["ALL", 'ALL']
64 logger.error "Error while loading distributions from '#{uri}': " + e.to_s