starting to use Rack
[chew.git] / target_api.rb
blobd3cb6919e19614f39dec10e395a8b63a0f8e59d9
1 module Actions::Products
2   before Index do |req|
3     req.session[:user].admin?
4   end
5   
6   class Index < Action
7     def setup
8       @products = Product.paginate(params[:page] || 1)
9     end
10     
11     def respond_json
12       @products.to_json
13     end
14     
15     # By default Action implements this behavior
16     # so no need to state it explicitly
17     #
18     # def respond_html
19     #   render
20     # end
21   end
23   class Update < PostAction
24     url_params ':id'
25     def setup
26       @product = Product.find(req.params[:id])
27     end
28   end
29 end