Peter Michaux
2006-Jul-23 02:01 UTC
[Rails] REST controller with up and down for model that acts_as_list
Hi, I have the following models class Department < ActiveRecord::Base has_many :products end class Product < ActiveRecord::Base belongs_to :department acts_as_list :scope => :department_id'' end When I look at a list of products for a particular department I have up and down buttons to re-order the products. Currently my controller is something like this class ProductController < ApplicationController def up Product.find(params[:id]).move_higher end def down Product.find(params[:id]).move_lower end end This doesn''t fit the the REST idea of only UPDATE for making changes. How do I rework this to be more REST friendly? Thanks, Peter
Rick Olson
2006-Jul-23 02:20 UTC
[Rails] REST controller with up and down for model that acts_as_list
> class ProductController < ApplicationController > def up > Product.find(params[:id]).move_higher > end > def down > Product.find(params[:id]).move_lower > end > end > > This doesn''t fit the the REST idea of only UPDATE for making changes. > How do I rework this to be more REST friendly?Not everything is necessarily REST. You could set up your simply_restful route like so: map.resource :product, :member => { :up => :post, :down => :post } This sets up routes for up and down as POST actions. POST /products/1;up POST /products/1;down up_product_url() down_product_url() -- Rick Olson http://techno-weenie.net
Peter Michaux
2006-Jul-23 03:20 UTC
[Rails] REST controller with up and down for model that acts_as_list
On 7/22/06, Rick Olson <technoweenie@gmail.com> wrote:> > Not everything is necessarily REST. You could set up your > simply_restful route like so: > > map.resource :product, :member => { :up => :post, :down => :post } > > This sets up routes for up and down as POST actions. > > POST /products/1;up > POST /products/1;down > > up_product_url() > down_product_url()Thanks, Rick. I am really trying to see where REST fits and where RPC works better. It seems to me like RPC is better in this case but with all of DHH''s hype about pure REST I am trying to use it wherever possible to try it out. Thanks again, Peter
Possibly Parallel Threads
- acts_as_list, move_higher, odd indexing behaviour?
- Need for multiple acts_as_list
- acts as list -- adding or moving new item to new location
- Admin and standard controllers RESTFully
- Difference between rake test:units and individually running ruby -I test test/unit/something_test.rb ?