Class: ActionDispatch::Routing::Mapper
- Inherits:
-
Object
- Object
- ActionDispatch::Routing::Mapper
- Defined in:
- lib/janus/routes.rb
Instance Method Summary collapse
-
#janus(*resources) ⇒ Object
Creates the routes for a Janus capable resource.
Instance Method Details
#janus(*resources) ⇒ Object
Creates the routes for a Janus capable resource.
Example:
MyApp::Application.routes.draw do
janus :users, :session => true, :registration => false
end
Options:
-
session
- true to generate session routes -
registration
- true to generate registration routes -
confirmation
- true to generate confirmation routes -
password
- true to generate password reset routes
Generated session routes:
new_user_session GET /users/sign_in(.:format) {:controller=>"users/sessions", :action=>"new"}
user_session POST /users/sign_in(.:format) {:controller=>"users/sessions", :action=>"create"}
destroy_user_session DELETE /users/sign_out(.:format) {:controller=>"users/sessions", :action=>"destroy"}
Generated registration routes:
new_user_registration GET /users/sign_up(.:format) {:controller=>"users/registrations", :action=>"new"}
user_registration POST /users(.:format) {:controller=>"users/registrations", :action=>"create"}
edit_user_registration GET /users/edit(.:format) {:controller=>"users/registrations", :action=>"edit"}
PUT /users(.:format) {:controller=>"users/registrations", :action=>"update"}
DELETE /users(.:format) {:controller=>"users/registrations", :action=>"destroy"}
Generated confirmation routes:
user_confirmation POST /users/confirmation(.:format) {:controller=>"users/confirmations", :action=>"create"}
new_user_confirmation GET /users/confirmation/new(.:format) {:controller=>"users/confirmations", :action=>"new"}
GET /users/confirmation(.:format) {:controller=>"users/confirmations", :action=>"show"}
Generated password reset routes:
user_password POST /users/password(.:format) {:controller=>"users/passwords", :action=>"create"}
new_user_password GET /users/password/new(.:format) {:controller=>"users/passwords", :action=>"new"}
edit_user_password GET /users/password/edit(.:format) {:controller=>"users/passwords", :action=>"edit"}
PUT /users/password(.:format) {:controller=>"users/passwords", :action=>"update"}
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/janus/routes.rb', line 46 def janus(*resources) ActionController::Base.send(:include, Janus::Helpers) unless ActionController::Base.include?(Janus::Helpers) ActionController::Base.send(:include, Janus::UrlHelpers) unless ActionController::Base.include?(Janus::UrlHelpers) = resources. resources.each do |plural| singular = plural.to_s.singularize if [:session] scope :path => plural, :controller => "#{plural}/sessions" do get "/sign_in(.:format)", :action => "new", :as => "new_#{singular}_session" post "/sign_in(.:format)", :action => "create", :as => "#{singular}_session" delete "/sign_out(.:format)", :action => "destroy", :as => "destroy_#{singular}_session" end end namespace plural, :as => singular do if [:registration] resource :registration, :except => [:index, :show], :path => "", :path_names => { :new => 'sign_up' } end resource :confirmation, :only => [:show, :new, :create] if [:confirmation] resource :password, :except => [:index, :show, :destroy] if [:password] yield if block_given? end ActionController::Base.janus(singular) end end |