added better error messages for search errors
This commit is contained in:
@@ -2,6 +2,7 @@ class PostsController < ApplicationController
|
|||||||
before_filter :member_only, :except => [:show, :index]
|
before_filter :member_only, :except => [:show, :index]
|
||||||
after_filter :save_recent_tags, :only => [:update]
|
after_filter :save_recent_tags, :only => [:update]
|
||||||
respond_to :html, :xml, :json
|
respond_to :html, :xml, :json
|
||||||
|
rescue_from PostSets::SearchError, :with => :search_error
|
||||||
|
|
||||||
def index
|
def index
|
||||||
@post_set = PostSets::Post.new(tag_query, params[:page])
|
@post_set = PostSets::Post.new(tag_query, params[:page])
|
||||||
@@ -38,6 +39,11 @@ class PostsController < ApplicationController
|
|||||||
end
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
def search_error(exception)
|
||||||
|
@exception = exception
|
||||||
|
render :action => "error"
|
||||||
|
end
|
||||||
|
|
||||||
def tag_query
|
def tag_query
|
||||||
params[:tags] || (params[:post] && params[:post][:tags])
|
params[:tags] || (params[:post] && params[:post][:tags])
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -1,7 +1,4 @@
|
|||||||
module PostSets
|
module PostSets
|
||||||
class SearchError < Exception
|
|
||||||
end
|
|
||||||
|
|
||||||
class Post < Base
|
class Post < Base
|
||||||
attr_reader :tag_array, :page
|
attr_reader :tag_array, :page
|
||||||
|
|
||||||
@@ -28,7 +25,7 @@ module PostSets
|
|||||||
|
|
||||||
def posts
|
def posts
|
||||||
if tag_array.size > 2 && !CurrentUser.is_privileged?
|
if tag_array.size > 2 && !CurrentUser.is_privileged?
|
||||||
raise SearchError
|
raise SearchError.new("Upgrade your account to search more than two tags at once")
|
||||||
end
|
end
|
||||||
|
|
||||||
@posts ||= ::Post.tag_match(tag_string).paginate(page)
|
@posts ||= ::Post.tag_match(tag_string).paginate(page)
|
||||||
|
|||||||
4
app/logical/post_sets/search_error.rb
Normal file
4
app/logical/post_sets/search_error.rb
Normal file
@@ -0,0 +1,4 @@
|
|||||||
|
module PostSets
|
||||||
|
class SearchError < Exception
|
||||||
|
end
|
||||||
|
end
|
||||||
1
app/views/posts/error.html.erb
Normal file
1
app/views/posts/error.html.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
<p>Error: <%= @exception.to_s %></p>
|
||||||
1
app/views/posts/error.json.erb
Normal file
1
app/views/posts/error.json.erb
Normal file
@@ -0,0 +1 @@
|
|||||||
|
{success: false, message: "<%= @exception.to_s %>"}
|
||||||
2
app/views/posts/error.xml.erb
Normal file
2
app/views/posts/error.xml.erb
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<result success="false"><%= @exception.to_s %></result>
|
||||||
Reference in New Issue
Block a user