<body><script type="text/javascript"> function setAttributeOnload(object, attribute, val) { if(window.addEventListener) { window.addEventListener('load', function(){ object[attribute] = val; }, false); } else { window.attachEvent('onload', function(){ object[attribute] = val; }); } } </script> <iframe src="http://www.blogger.com/navbar.g?targetBlogID=4684235500622716427&amp;blogName=Caiwangqin&#39;s+blog&amp;publishMode=PUBLISH_MODE_HOSTED&amp;navbarType=BLUE&amp;layoutType=CLASSIC&amp;searchRoot=http://blog.caiwangqin.com/search&amp;blogLocale=zh_CN&amp;v=1&amp;homepageUrl=http://blog.caiwangqin.com/&amp;vt=3393395200455623441" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" height="30px" width="100%" id="navbar-iframe" allowtransparency="true" title="Blogger 导航和搜索"></iframe> <div></div>

Caiwangqin's blog

Focus on Web2.0, Business, Architecture, Agile, Technic and beyond…

Ruby on Rails 用户角色管理

2007年4月11日 星期三

使用acts_as_authenticated + authorization plugin 实现 Ruby on Rails 用户角色管理,step-by-step :


$ mysqladmin create auth_development

$ rails auth

$ ./script/plugin install http://svn.techno-weenie.net/projects/plugins/acts_as_authenticated 

$ ./script/plugin install http://svn.writertopia.com/svn/plugins/authorization

$ ./script/generate authenticated user account

$ ./script/generate role_model role

$ rake db:migrate

added following to my environment.rb:



AUTHORIZATION_MIXIN = “object roles”

DEFAULT_REDIRECTION_HASH = { :controller => ‘account’, :action =>

‘login’ }


added those to my user model:



  acts_as_authorized_user

  acts_as_authorizable


and this to test controller:



class TestController < ApplicationController

 permit "site_admin or moderator"

 

 def index

  render :text => “okok”

 end

end


$ ./script/server


标签:

posted by Jesse Cai, 上午10:48

0 Comments:

发表评论

订阅 帖子评论 [Atom]

<< 主页