restful_authentication

关键字: rails restful authentication
restful_authentication是Rails的一个认证插件,基于REST方式,适合RESTful的geek
安装:
ruby代码
  1. ruby script/plugin install http://svn.techno-weenie.net/projects/plugins/restful_authentication/  
  2. ruby script/generate authenticated users sessions  
可选择性的修改routes:
ruby代码
  1. # routes.rb  
  2. ActionController::Routing::Routes.draw do |map|  
  3.   map.home '', :controller => 'home', :action => 'index'  
  4.   
  5.   map.resources :users  
  6.   map.resource  :session  
  7.   map.signup '/signup', :controller => 'users', :action => 'new'  
  8.   map.login  '/login', :controller => 'session', :action => 'new'  
  9.   map.logout '/logout', :controller => 'session', :action => 'destroy'  
  10. end  
一些helper方法:
ruby代码
  1. <!-- home/index.rhtml -->  
  2. <h1>Welcome</h1>  
  3.   
  4. <% if logged_in? %>  
  5.   <p><strong>You are logged in as <%=h current_user.login %></strong></p>  
  6.   <p><%= link_to 'Logout', logout_path %></p>  
  7. <% else %>  
  8.   <p><strong>You are currently not logged in.</strong></p>  
  9.   <p>  
  10.     <%= link_to 'Login', login_path %> or  
  11.     <%= link_to 'Sign Up', signup_path %>  
  12.   </p>  
  13. <% end %>  
posted @ 2009-07-10 14:26  麦飞  阅读(538)  评论(0编辑  收藏  举报