{"id":22808348,"url":"https://github.com/sixarm/sixarm_ruby_current_user_id","last_synced_at":"2026-05-09T17:33:55.606Z","repository":{"id":1123001,"uuid":"995878","full_name":"SixArm/sixarm_ruby_current_user_id","owner":"SixArm","description":"SixArm.com » Ruby » Get the current user id of a Ruby on Rails app","archived":false,"fork":false,"pushed_at":"2023-09-15T19:27:53.000Z","size":321,"stargazers_count":1,"open_issues_count":0,"forks_count":0,"subscribers_count":3,"default_branch":"main","last_synced_at":"2025-02-06T00:26:07.770Z","etag":null,"topics":["gem","id","rails","ruby","user"],"latest_commit_sha":null,"homepage":"http://sixarm.com","language":"Ruby","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"other","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/SixArm.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGES.md","contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":"CODEOWNERS","security":null,"support":null,"governance":null}},"created_at":"2010-10-18T00:22:27.000Z","updated_at":"2023-05-22T14:10:54.000Z","dependencies_parsed_at":"2023-07-05T20:16:43.115Z","dependency_job_id":null,"html_url":"https://github.com/SixArm/sixarm_ruby_current_user_id","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SixArm%2Fsixarm_ruby_current_user_id","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SixArm%2Fsixarm_ruby_current_user_id/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SixArm%2Fsixarm_ruby_current_user_id/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/SixArm%2Fsixarm_ruby_current_user_id/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/SixArm","download_url":"https://codeload.github.com/SixArm/sixarm_ruby_current_user_id/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246379366,"owners_count":20767696,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["gem","id","rails","ruby","user"],"created_at":"2024-12-12T11:09:18.544Z","updated_at":"2026-05-09T17:33:50.579Z","avatar_url":"https://github.com/SixArm.png","language":"Ruby","funding_links":[],"categories":[],"sub_categories":[],"readme":"# SixArm.com → Ruby → \u003cbr\u003e CurrentUserId module for Rails sessions\n\n* Doc: \u003chttp://sixarm.com/sixarm_ruby_current_user_id/doc\u003e\n* Gem: \u003chttp://rubygems.org/gems/sixarm_ruby_current_user_id\u003e\n* Repo: \u003chttp://github.com/sixarm/sixarm_ruby_current_user_id\u003e\n\u003c!--header-shut--\u003e\n\n## Introduction\n\nGet and set the current user id in the Rails session array.\n\nWhen you set the current user id:\n - this sets session[:current_user_id] to the id\n - this sets @current_user_id to the id\n\nFor docs go to \u003chttp://sixarm.com/sixarm_ruby_current_user_id/doc\u003e\n\nWant to help? We're happy to get pull requests.\n\n\n\u003c!--install-open--\u003e\n\n## Install\n\n### Gem\n\nTo install this gem in your shell or terminal:\n\n    gem install sixarm_ruby_current_user_id\n\n### Gemfile\n\nTo add this gem to your Gemfile:\n\n    gem 'sixarm_ruby_current_user_id'\n\n### Require\n\nTo require the gem in your code:\n\n    require 'sixarm_ruby_current_user_id'\n\n\u003c!--install-shut--\u003e\n\n\n## Example code\n\n    self.current_user_id = 1\n    #=\u003e @current_user_id = session[:current_user_id] = 1\n\n\n## Example controller\n\n    class MyController \u003c ApplicationController\n\n      def sign_in(user)\n        self.current_user_id = user.id\n      end\n\n      def sign_out\n        self.current_user_id = nil\n      end\n\n      def is_anyone_using_this?\n        current_user_id?\n      end\n\n    end\n\n\n## Example of reloading\n\nFor fast speed, we memoize the current_user_id: \nwe use the fast instance variable @current_user_id\nrather than the slower session[:current_user_id].\n\nTo reload @current_user_id from session[:current_user_id], \nwe use the :reload parameter like this:\n\n    current_user_id(:reload =\u003e true)\n\n\n## Why use the self prefix?\n\nWhen we set variables, we must use the \"self\" prefix because Ruby uses this to do method dispatch.\n\nRight:\n\n    self.current_user_id = 1\n\nWrong:\n\n    current_user_id = 1\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsixarm%2Fsixarm_ruby_current_user_id","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsixarm%2Fsixarm_ruby_current_user_id","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsixarm%2Fsixarm_ruby_current_user_id/lists"}