Check my Ruby on Rails routes.rb file -
i started programming in ruby on rails, , wondering if of on routes.rb file using far , tell me if on thinking this.
i aware of whole restful approach in ror , trying stick it, not sure if on track. far application has following functionality:
- user registration
- user activation (via email link)
- user can request activation resent
- user log in
- user log out
- user requests password reset (gets email)
- basic ucp (change email , password)
i using lot of redirect_to *_url , *_path, want lot of named routes. trying explicitly declare routes allowed. input.
myapp::application.routes.draw 'home' => 'pages#index', :as => 'home' 'testing' => 'pages#testing', :as => 'testing' 'register' => 'users#new', :as => 'register' post 'users/create' resources :users, :only => [ :new, :create ] 'activation' => 'activations#new', :as => 'activation' 'activate/:token' => 'activations#activate', :as => 'activate' post 'activations/edit' resources :activations, :only => [ :new, :activate, :edit ] 'login' => 'sessions#new', :as => 'login' 'logout' => 'sessions#destroy', :as => 'logout' 'sessions/destroy' resources :sessions, :only => [ :new, :create, :destroy ] 'forgot_password' => 'resets#new', :as => 'forgot_password' post 'resets/create' 'activate_password/:token' => 'resets#activate', :as => 'activate_password' put 'save_password' => 'resets#save', :as => 'save_password' resources :resets, :only => [ :new, :create, :activate, :save ] 'ucp' => 'ucp#show', :as => 'ucp' post 'ucp_update' => 'ucp#update', :as => 'ucp_update' resources :ucp, :only => [ :show, :update ] root :to => 'pages#index' end
when use resources
, automatically makes named routes you. won't go through entire routes file, 1 example:
'activation' => 'activations#new', :as => 'activation' 'activate/:token' => 'activations#activate', :as => 'activate' post 'activations/edit' resources :activations, :only => [ :new, :activate, :edit ]
could be:
resources :activations, :only => [:new, :edit] 'activate', :on => :member end
which produce new_activation_path, edit_activation_path, , activate_activation_path
go rails routing guide lot of cool stuff can in routes. example, if want use "register" instead of "new" users paths:
resources :users, :only => [:new, :create], :path_names => [:new => 'register']
Comments
Post a Comment