<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> <div id="navbar-iframe-container"></div> <script type="text/javascript" src="https://apis.google.com/js/platform.js"></script> <script type="text/javascript"> gapi.load("gapi.iframes:gapi.iframes.style.bubble", function() { if (gapi.iframes && gapi.iframes.getContext) { gapi.iframes.getContext().openChild({ url: 'https://www.blogger.com/navbar.g?targetBlogID\x3d4684235500622716427\x26blogName\x3dCaiwangqin\x27s+blog\x26publishMode\x3dPUBLISH_MODE_HOSTED\x26navbarType\x3dBLUE\x26layoutType\x3dCLASSIC\x26searchRoot\x3dhttp://blog.caiwangqin.com/search\x26blogLocale\x3dzh_CN\x26v\x3d2\x26homepageUrl\x3dhttp://blog.caiwangqin.com/\x26vt\x3d3393395200455623441', where: document.getElementById("navbar-iframe-container"), id: "navbar-iframe", messageHandlersFilter: gapi.iframes.CROSS_ORIGIN_IFRAMES_FILTER, messageHandlers: { 'blogger-ping': function() {} } }); } }); </script>

Caiwangqin's blog

Focus on Life, Cloud Service, Smart Hardware, Architecture, 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 Caiwangqin, 10:48

0 Comments:

发表评论

订阅 博文评论 [Atom]

<< 主页