[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"project-7714":3},{"id":4,"name":5,"fullName":6,"owner":7,"repo":5,"description":8,"homepage":9,"htmlUrl":10,"language":11,"languages":10,"totalLinesOfCode":10,"stars":12,"forks":13,"watchers":14,"openIssues":15,"contributorsCount":16,"subscribersCount":16,"size":16,"stars1d":16,"stars7d":17,"stars30d":18,"stars90d":16,"forks30d":16,"starsTrendScore":17,"compositeScore":19,"rankGlobal":10,"rankLanguage":10,"license":20,"archived":21,"fork":21,"defaultBranch":22,"hasWiki":21,"hasPages":21,"topics":23,"createdAt":10,"pushedAt":10,"updatedAt":26,"readmeContent":27,"aiSummary":28,"trendingCount":16,"starSnapshotCount":16,"syncStatus":29,"lastSyncTime":30,"discoverSource":31},7714,"cancancan","CanCanCommunity\u002Fcancancan","CanCanCommunity","The authorization Gem for Ruby on Rails.","",null,"Ruby",5689,636,92,61,0,1,14,39.41,"MIT License",false,"develop",[24,5,25],"authorization","rails","2026-06-12 02:01:43","# CanCanCan\n\n\u003Cimg src=\".\u002Flogo\u002Fcancancan.png\" width=\"200\" \u002F>\n\n[![Gem Version](https:\u002F\u002Fbadge.fury.io\u002Frb\u002Fcancancan.svg)](http:\u002F\u002Fbadge.fury.io\u002Frb\u002Fcancancan)\n[![Github Actions badge](https:\u002F\u002Fgithub.com\u002FCanCanCommunity\u002Fcancancan\u002Factions\u002Fworkflows\u002Ftest.yml\u002Fbadge.svg)](https:\u002F\u002Fgithub.com\u002FCanCanCommunity\u002Fcancancan\u002Factions\u002Fworkflows\u002Ftest.yml\u002Fbadge.svg)\n[![Code Climate Badge](https:\u002F\u002Fcodeclimate.com\u002Fgithub\u002FCanCanCommunity\u002Fcancancan.svg)](https:\u002F\u002Fcodeclimate.com\u002Fgithub\u002FCanCanCommunity\u002Fcancancan)\n\n[Developer guide](.\u002Fdocs\u002FREADME.md) |\n[RDocs](https:\u002F\u002Fwww.rubydoc.info\u002Fgithub\u002FCanCanCommunity\u002Fcancancan) |\n[Screencast 1](http:\u002F\u002Frailscasts.com\u002Fepisodes\u002F192-authorization-with-cancan) |\n[Screencast 2](https:\u002F\u002Fwww.youtube.com\u002Fwatch?v=cTYu-OjUgDw)\n\nCanCanCan is an authorization library for Ruby and Ruby on Rails which restricts what\nresources a given user is allowed to access.\n\nAll permissions can be defined in one or multiple ability files and not duplicated across controllers, views,\nand database queries, keeping your permissions logic in one place for easy maintenance and testing.\n\nIt consists of two main parts:\n1. **Authorizations library** that allows you to define the rules to access different objects,\nand provides helpers to check for those permissions.\n\n2. **Rails helpers** to simplify the code in Rails Controllers by performing the loading and checking of permissions\nof models automatically and reduce duplicated code.\n\n## Our sponsors\n\u003Cbr\u002F>\n\u003Ca href=\"https:\u002F\u002Fwww.pennylane.com\u002F\" target=\"_blank\">\n  \u003Cimg src=\".\u002Flogo\u002Fpennylane.svg\" alt=\"Pennylane\" height=\"50\"\u002F>\n\u003C\u002Fa>\n\u003Cbr \u002F>\n\u003Cbr \u002F>\n\u003Cbr \u002F>\n\u003Ca href=\"https:\u002F\u002Fmembean.com\u002F\" target=\"_blank\">\n  \u003Cimg src=\".\u002Flogo\u002Fmembean.svg\" alt=\"Membean\" height=\"45\"\u002F>\n\u003C\u002Fa>\n\u003Cbr\u002F>\n\u003Cbr\u002F>\n\u003Cbr\u002F>\n\u003Ca href=\"https:\u002F\u002Fjobs.goboony.com\u002Fo\u002Ffull-stack-ruby-on-rails-engineer\" target=\"_blank\">\n  \u003Cimg src=\".\u002Flogo\u002Fgoboony.png\" alt=\"Goboony\" height=\"50\"\u002F>\n\u003C\u002Fa>\n\u003Cbr \u002F>\n\u003Cbr \u002F>\n\u003Cbr \u002F>\n\u003Ca href=\"https:\u002F\u002Fwww.renuo.ch\" target=\"_blank\">\n  \u003Cimg src=\".\u002Flogo\u002Frenuo.png\" alt=\"Renuo AG\" height=\"50\"\u002F>\n\u003C\u002Fa>\n\u003Cbr \u002F>\n\u003Cbr \u002F>\n\nDo you want to sponsor CanCanCan and show your logo here?\nCheck our [Sponsors Page](https:\u002F\u002Fgithub.com\u002Fsponsors\u002Fcoorasse).\n\nHead to our complete [Developer Guide](.\u002Fdocs\u002FREADME.md) to learn how to use CanCanCan in details.\n\n## Installation\n\nAdd this to your Gemfile:\n\n    gem 'cancancan'\n\nand run the `bundle install` command.\n\n## Define Abilities\n\nUser permissions are defined in an `Ability` class.\n\n    rails g cancan:ability\n\nHere follows an example of rules defined to read a Post model.\n```ruby\nclass Ability\n  include CanCan::Ability\n\n  def initialize(user)\n    can :read, Post, public: true\n\n    return unless user.present?  # additional permissions for logged in users (they can read their own posts)\n    can :read, Post, user: user\n\n    return unless user.admin?  # additional permissions for administrators\n    can :read, Post\n  end\nend\n```\n\n## Check Abilities\n\nThe current user's permissions can then be checked using the `can?` and `cannot?` methods in views and controllers.\n\n```erb\n\u003C% if can? :read, @post %>\n  \u003C%= link_to \"View\", @post %>\n\u003C% end %>\n```\n\n## Fetching records\n\nOne of the key features of CanCanCan, compared to other authorization libraries,\nis the possibility to retrieve all the objects that the user is authorized to access.\nThe following:\n\n```ruby\n  @posts = Post.accessible_by(current_ability)\n```\n\nwill use your rules to ensure that the user retrieves only a list of posts that can be read.\n\n## Controller helpers\n\nThe `authorize!` method in the controller will raise an exception if the user is not able to perform the given action.\n\n```ruby\ndef show\n  @post = Post.find(params[:id])\n  authorize! :read, @post\nend\n```\n\nSetting this for every action can be tedious, therefore the `load_and_authorize_resource` method is provided to\nautomatically authorize all actions in a RESTful style resource controller.\nIt will use a before action to load the resource into an instance variable and authorize it for every action.\n\n```ruby\nclass PostsController \u003C ApplicationController\n  load_and_authorize_resource\n\n  def show\n    # @post is already loaded and authorized\n  end\n\n  def index\n    # @posts is already loaded with all posts the user is authorized to read\n  end\nend\n```\n\n## Documentation\n\nHead to our complete [Developer Guide](.\u002Fdocs\u002FREADME.md) to learn how to use CanCanCan in details.\n\n## Questions?\n\nIf you have any question or doubt regarding CanCanCan which you cannot find the solution to in the\n[documentation](.\u002Fdocs\u002FREADME.md), please\n[open a question on Stackoverflow](http:\u002F\u002Fstackoverflow.com\u002Fquestions\u002Fask?tags=cancancan) with tag\n[cancancan](http:\u002F\u002Fstackoverflow.com\u002Fquestions\u002Ftagged\u002Fcancancan)\n\n## Bugs?\n\nIf you find a bug please add an [issue on GitHub](https:\u002F\u002Fgithub.com\u002FCanCanCommunity\u002Fcancancan\u002Fissues) or fork the project and send a pull request.\n\n## Development\n\nCanCanCan uses [appraisals](https:\u002F\u002Fgithub.com\u002Fthoughtbot\u002Fappraisal) to test the code base against multiple versions\nof Rails, as well as the different model adapters.\n\nWhen first developing, you need to run `bundle install` and then `bundle exec appraisal install`, to install the different sets.\n\nYou can then run all appraisal files (like CI does), with `appraisal rake` or just run a specific set `DB='sqlite' bundle exec appraisal activerecord_5.2.2 rake`.\n\nIf you'd like to run a specific set of tests within a specific file or folder you can use `DB='sqlite' SPEC=path\u002Fto\u002Ffile\u002For\u002Ffolder bundle exec appraisal activerecord_5.2.2 rake`.\n\nIf you use RubyMine, you can run RSpec tests by configuring the RSpec configuration template like this:\n![rubymine_rspec.png](rubymine_rspec.png)\n\nSee the [CONTRIBUTING](.\u002FCONTRIBUTING.md) for more information.\n\n## Special Thanks\n\nThanks to our Sponsors and to all the [CanCanCan contributors](https:\u002F\u002Fgithub.com\u002FCanCanCommunity\u002Fcancancan\u002Fcontributors).\nSee the [CHANGELOG](https:\u002F\u002Fgithub.com\u002FCanCanCommunity\u002Fcancancan\u002Fblob\u002Fmain\u002FCHANGELOG.md) for the full list.\n","CanCanCan 是一个用于 Ruby 和 Ruby on Rails 的授权库，用于限制特定用户对资源的访问权限。其核心功能包括定义用户权限规则，并提供检查这些权限的帮助方法，从而将权限逻辑集中管理，便于维护和测试。CanCanCan 由授权库和 Rails 帮助器两部分组成：授权库允许开发者为不同对象设置访问规则；Rails 帮助器则简化了控制器中的代码，自动处理模型的权限加载与检查，减少重复代码。该库适用于需要实现细粒度访问控制的 Web 应用场景，特别是基于 Rails 框架开发的应用程序。",2,"2026-06-11 03:13:57","top_language"]