1
0
Fork 0
forked from OpenNeo/impress
impress/app/controllers/items_controller.rb

42 lines
1.1 KiB
Ruby
Raw Normal View History

2010-05-15 10:47:46 -07:00
class ItemsController < ApplicationController
2010-06-07 17:02:46 -07:00
before_filter :set_query
2010-05-15 10:47:46 -07:00
def index
if params.has_key?(:q)
begin
2010-06-22 10:00:55 -07:00
if params[:per_page]
per_page = params[:per_page].to_i
per_page = 50 if per_page && per_page > 50
else
per_page = nil
end
@results = Item.search(@query).alphabetize.paginate :page => params[:page], :per_page => per_page
respond_to do |format|
format.html { render }
format.js { render :json => {:items => @results, :total_pages => @results.total_pages}, :callback => params[:callback] }
end
2010-05-15 10:47:46 -07:00
rescue
2010-06-22 10:00:55 -07:00
respond_to do |format|
format.html { flash.now[:error] = $!.message }
format.js { render :json => {:error => $!.message}, :callback => params[:callback] }
2010-06-22 10:00:55 -07:00
end
2010-05-15 10:47:46 -07:00
end
else
respond_to do |format|
format.html { render }
format.js { render :json => {:error => '$q required'}}
end
2010-05-15 10:47:46 -07:00
end
end
2010-05-15 17:46:41 -07:00
def show
@item = Item.find params[:id]
end
2010-06-07 17:02:46 -07:00
private
def set_query
@query = params[:q]
end
2010-05-15 10:47:46 -07:00
end