Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 4259

Show
Ignore:
Timestamp:
04/24/06 21:30:18 (3 years ago)
Author:
minam
Message:

simply_restful: use path_prefix and name_prefix separately, instead of a single "prefix" key

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • plugins/simply_restful/lib/simply_restful/routes.rb

    r4258 r4259  
    44      plural = entity.to_s.pluralize 
    55 
    6       collection = options.delete(:collection) || {} 
    7       member     = options.delete(:member) || {} 
    8       new        = options.delete(:new) || true 
    9       prefix     = options.delete(:prefix) 
     6      collection  = options.delete(:collection) || {} 
     7      member      = options.delete(:member) || {} 
     8      new         = options.delete(:new) || true 
     9      path_prefix = options.delete(:path_prefix) 
     10      name_prefix = options.delete(:name_prefix) 
    1011 
    1112      member[:edit] = :get 
     
    2324      (member_methods[:delete] ||= []).unshift :delete 
    2425 
    25       path = "#{prefix}/#{plural}" 
     26      path = "#{path_prefix}/#{plural}" 
    2627 
    2728      collection_path = path 
     
    3435          route_options = requirements_for(method) 
    3536          list.each do |action| 
    36             map.named_route("#{action}_#{plural}", "#{collection_path};#{action}", route_options.merge(:action => action.to_s)) 
     37            map.named_route("#{name_prefix}#{action}_#{plural}", "#{collection_path};#{action}", route_options.merge(:action => action.to_s)) 
    3738          end 
    3839          map.connect(collection_path, route_options.merge(:action => primary)) unless primary.blank? 
    3940        end 
    4041 
    41         map.named_route(plural, collection_path, :action => "index", :require => { :method => :get }) 
     42        map.named_route("#{name_prefix}#{plural}", collection_path, :action => "index", :require => { :method => :get }) 
    4243 
    4344        new_methods.each do |method, list| 
     
    4748            name = "new_#{entity}" 
    4849            name = "#{action}_#{name}" unless action == :new 
    49             map.named_route(name, path, route_options.merge(:action => action.to_s)) 
     50            map.named_route("#{name_prefix}#{name}", path, route_options.merge(:action => action.to_s)) 
    5051          end 
    5152        end 
     
    5556          primary = list.shift.to_s if method != :get 
    5657          list.each do |action| 
    57             map.named_route("#{action}_#{entity}", "#{member_path};#{action}", route_options.merge(:action => action.to_s)) 
     58            map.named_route("#{name_prefix}#{action}_#{entity}", "#{member_path};#{action}", route_options.merge(:action => action.to_s)) 
    5859          end 
    5960          map.connect(member_path, route_options.merge(:action => primary)) unless primary.blank? 
    6061        end 
    6162 
    62         map.named_route(entity.to_s, member_path, :action => "show", :require => { :method => :get }) 
     63        map.named_route("#{name_prefix}#{entity}", member_path, :action => "show", :require => { :method => :get }) 
    6364      end 
    6465    end 
  • plugins/simply_restful/README

    r4258 r4259  
    7878routes: 
    7979 
    80   map.resource :message, :prefix => "/thread/:thread_id" 
     80  map.resource :message, :path_prefix => "/thread/:thread_id" 
    8181  # --> GET /thread/7/messages/1 
    8282  
     
    9797  #     also adds a url named "preview_new_message" 
    9898  # --> /messages/new can be invoked via any request method 
     99 
     100  map.resource :message, :controller => "categories", 
     101        :path_prefix => "/category/:category_id", 
     102        :name_prefix => "category_" 
     103  # --> GET /categories/7/messages/1 
     104  #     has named route "category_message"