aboutsummaryrefslogtreecommitdiffstats
path: root/app/controllers/application_controller.rb
diff options
context:
space:
mode:
authorSeb Bacon <seb.bacon@gmail.com>2012-05-15 12:55:09 +0100
committerSeb Bacon <seb.bacon@gmail.com>2012-05-15 12:55:09 +0100
commit23816aff9e970e1264b2231757702f648f05e30c (patch)
treea286daaa01c1ca2bb5f8ca7035d3370541148f43 /app/controllers/application_controller.rb
parent8c5a6f4dc2d174ed5190719d952b39720d3bf362 (diff)
parent5097146ff016b2aaa9d3dc29f3ec65db0aadbb72 (diff)
Merge branch 'develop' into feature/follow-buttons
Conflicts: app/models/track_mailer.rb app/models/track_thing.rb
Diffstat (limited to 'app/controllers/application_controller.rb')
-rw-r--r--app/controllers/application_controller.rb44
1 files changed, 28 insertions, 16 deletions
diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb
index 0d0cca3e4..e305e90f4 100644
--- a/app/controllers/application_controller.rb
+++ b/app/controllers/application_controller.rb
@@ -20,7 +20,7 @@ class ApplicationController < ActionController::Base
# Send notification email on exceptions
include ExceptionNotification::Notifiable
-
+
# Note: a filter stops the chain if it redirects or renders something
before_filter :authentication_check
before_filter :set_gettext_locale
@@ -34,7 +34,7 @@ class ApplicationController < ActionController::Base
def set_vary_header
response.headers['Vary'] = 'Cookie'
end
-
+
helper_method :anonymous_cache, :short_cache, :medium_cache, :long_cache
def anonymous_cache(time)
if session[:user_id].nil?
@@ -118,8 +118,20 @@ class ApplicationController < ActionController::Base
# Override default error handler, for production sites.
def rescue_action_in_public(exception)
+ # Call `set_view_paths` from the theme, if it exists.
+ # Normally, this is called by the theme itself in a
+ # :before_filter, but when there's an error, this doesn't
+ # happen. By calling it here, we can ensure error pages are
+ # still styled according to the theme.
+ begin
+ set_view_paths
+ rescue NameError => e
+ if !(e.message =~ /undefined local variable or method `set_view_paths'/)
+ raise
+ end
+ end
# Make sure expiry time for session is set (before_filters are
- # otherwise missed by this override)
+ # otherwise missed by this override)
session_remember_me
case exception
when ActiveRecord::RecordNotFound, ActionController::UnknownAction, ActionController::RoutingError
@@ -141,13 +153,13 @@ class ApplicationController < ActionController::Base
alias original_rescue_action_locally rescue_action_locally
def rescue_action_locally(exception)
# Make sure expiry time for session is set (before_filters are
- # otherwise missed by this override)
+ # otherwise missed by this override)
session_remember_me
# Display default, detailed error for developers
original_rescue_action_locally(exception)
end
-
+
def local_request?
false
end
@@ -208,7 +220,7 @@ class ApplicationController < ActionController::Base
end
end
- # get the local locale
+ # get the local locale
def locale_from_params(*args)
if params[:show_locale]
params[:show_locale]
@@ -308,7 +320,7 @@ class ApplicationController < ActionController::Base
end
end
- #
+ #
def check_read_only
read_only = MySociety::Config.get('READ_ONLY', '')
if !read_only.empty?
@@ -337,7 +349,7 @@ class ApplicationController < ActionController::Base
@http_auth_user = admin_http_auth_user
end
- # Convert URL name for sort by order, to Xapian query
+ # Convert URL name for sort by order, to Xapian query
def order_to_sort_by(sortby)
if sortby.nil?
return [nil, nil]
@@ -353,7 +365,7 @@ class ApplicationController < ActionController::Base
end
# Function for search
- def perform_search(models, query, sortby, collapse, per_page = 25, this_page = nil)
+ def perform_search(models, query, sortby, collapse, per_page = 25, this_page = nil)
@query = query
@sortby = sortby
@@ -389,7 +401,7 @@ class ApplicationController < ActionController::Base
collapse = 'request_collapse'
end
options = {
- :offset => (@page - 1) * @per_page,
+ :offset => (@page - 1) * @per_page,
:limit => @per_page,
:sort_by_prefix => nil,
:sort_by_ascending => true,
@@ -408,7 +420,7 @@ class ApplicationController < ActionController::Base
if e.message =~ /^QueryParserError: Wildcard/
# Wildcard expands to too many terms
logger.info "Wildcard query '#{query.strip + '*'}' caused: #{e.message}"
-
+
user_query = ActsAsXapian.query_parser.parse_query(
query,
Xapian::QueryParser::FLAG_LOVEHATE |
@@ -437,8 +449,8 @@ class ApplicationController < ActionController::Base
def param_exists(item)
return params[item] && !params[item].empty?
- end
-
+ end
+
def get_request_variety_from_params
query = ""
sortby = "newest"
@@ -463,7 +475,7 @@ class ApplicationController < ActionController::Base
def get_status_from_params
query = ""
- if params[:latest_status]
+ if params[:latest_status]
statuses = []
if params[:latest_status].class == String
params[:latest_status] = [params[:latest_status]]
@@ -514,7 +526,7 @@ class ApplicationController < ActionController::Base
query = ""
tags = []
if param_exists(:tags)
- params[:tags].split().each do |tag|
+ params[:tags].split().each do |tag|
tags << "tag:#{tag}"
end
end
@@ -523,7 +535,7 @@ class ApplicationController < ActionController::Base
end
return query
end
-
+
def make_query_from_params
query = params[:query] || "" if query.nil?
query += get_date_range_from_params