forked from OpenNeo/impress
distribute items as jsonp
This commit is contained in:
parent
8e69d38ff7
commit
fbba36005e
3 changed files with 26 additions and 2 deletions
|
@ -4,9 +4,22 @@ class ItemsController < ApplicationController
|
|||
def index
|
||||
if params.has_key?(:q)
|
||||
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
|
||||
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
|
||||
|
|
|
@ -55,6 +55,16 @@ class Item < ActiveRecord::Base
|
|||
end
|
||||
end
|
||||
|
||||
def as_json(options = {})
|
||||
{
|
||||
:description => description,
|
||||
:id => id,
|
||||
:name => name,
|
||||
:thumbnail_url => thumbnail_url,
|
||||
:zones_restrict => zones_restrict
|
||||
}
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
SearchFilterScopes = []
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
OpenneoImpressItems::Application.routes.draw do |map|
|
||||
match '/' => 'items#index', :as => :items
|
||||
match '/index.js' => 'items#index', :format => :js
|
||||
match '/:id' => 'items#show', :as => :item
|
||||
|
||||
match '/items/:item_id/swf_assets.json' => 'swf_assets#index', :as => :item_swf_assets
|
||||
|
|
Loading…
Reference in a new issue