distribute items as jsonp

This commit is contained in:
Emi Matchu 2010-06-22 13:00:55 -04:00
parent 8e69d38ff7
commit fbba36005e
3 changed files with 26 additions and 2 deletions

View file

@ -4,9 +4,22 @@ class ItemsController < ApplicationController
def index def index
if params.has_key?(:q) if params.has_key?(:q)
begin begin
@results = Item.search(@query).alphabetize.paginate :page => params[:page] 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
rescue rescue
flash.now[:alert] = $!.message respond_to do |format|
format.html { flash.now[:error] = $!.message }
format.js { render :json => {:error => $!.message}, :status => :bad_request, :callback => params[:callback] }
end
end end
end end
end end

View file

@ -55,6 +55,16 @@ class Item < ActiveRecord::Base
end end
end end
def as_json(options = {})
{
:description => description,
:id => id,
:name => name,
:thumbnail_url => thumbnail_url,
:zones_restrict => zones_restrict
}
end
private private
SearchFilterScopes = [] SearchFilterScopes = []

View file

@ -1,5 +1,6 @@
OpenneoImpressItems::Application.routes.draw do |map| OpenneoImpressItems::Application.routes.draw do |map|
match '/' => 'items#index', :as => :items match '/' => 'items#index', :as => :items
match '/index.js' => 'items#index', :format => :js
match '/:id' => 'items#show', :as => :item match '/:id' => 'items#show', :as => :item
match '/items/:item_id/swf_assets.json' => 'swf_assets#index', :as => :item_swf_assets match '/items/:item_id/swf_assets.json' => 'swf_assets#index', :as => :item_swf_assets