{"action":"created","issue":{"url":"https://api.github.com/repos/RolifyCommunity/rolify/issues/331","labels_url":"https://api.github.com/repos/RolifyCommunity/rolify/issues/331/labels{/name}","comments_url":"https://api.github.com/repos/RolifyCommunity/rolify/issues/331/comments","events_url":"https://api.github.com/repos/RolifyCommunity/rolify/issues/331/events","html_url":"https://github.com/RolifyCommunity/rolify/issues/331","id":69590145,"number":331,"title":"Getting *NoMethodError: undefined method `name' for nil:NilClass* after user.add_role :admin","user":{"login":"aftabaig","id":3858426,"avatar_url":"https://avatars.githubusercontent.com/u/3858426?v=3","gravatar_id":"","url":"https://api.github.com/users/aftabaig","html_url":"https://github.com/aftabaig","followers_url":"https://api.github.com/users/aftabaig/followers","following_url":"https://api.github.com/users/aftabaig/following{/other_user}","gists_url":"https://api.github.com/users/aftabaig/gists{/gist_id}","starred_url":"https://api.github.com/users/aftabaig/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/aftabaig/subscriptions","organizations_url":"https://api.github.com/users/aftabaig/orgs","repos_url":"https://api.github.com/users/aftabaig/repos","events_url":"https://api.github.com/users/aftabaig/events{/privacy}","received_events_url":"https://api.github.com/users/aftabaig/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":2,"created_at":"2015-04-20T13:44:05Z","updated_at":"2015-09-15T21:46:01Z","closed_at":null,"body":"In my project(Rails 4.1.1) I am using Devise, CanCan, Rolify. \r\nThere is trouble with using Rolify.\r\n\r\nclass User < ActiveRecord::Base\r\n  rolify\r\n...\r\nMigrations for roles and users_roles have already done. When I want to add_role to user in rails console:\r\n\r\nUser.last.add_role :admin\r\nI receive this error.\r\n\r\n   User Load (0.6ms)  SELECT  `users`.* FROM `users`  WHERE `users`.`deleted_at` IS NULL  ORDER BY `users`.`id` DESC LIMIT 1\r\n  Role Load (0.6ms)  SELECT  `roles`.* FROM `roles`  WHERE `roles`.`name` = 'admin' AND `roles`.`resource_type` IS NULL AND `roles`.`resource_id` IS NULL  ORDER BY `roles`.`id` ASC LIMIT 1\r\n  Role Exists (0.5ms)  SELECT  1 AS one FROM `roles` INNER JOIN `users_roles` ON `roles`.`id` = `users_roles`.`role_id` WHERE `users_roles`.`user_id` = 7 AND `roles`.`id` = 1 LIMIT 1\r\n   (0.5ms)  SELECT `roles`.id FROM `roles` INNER JOIN `users_roles` ON `roles`.`id` = `users_roles`.`role_id` WHERE `users_roles`.`user_id` = 7\r\n  Role Load (0.4ms)  SELECT  `roles`.* FROM `roles`  WHERE `roles`.`id` = 1 LIMIT 1\r\n  Role Load (0.6ms)  SELECT `roles`.* FROM `roles` INNER JOIN `users_roles` ON `roles`.`id` = `users_roles`.`role_id` WHERE `users_roles`.`user_id` = 7\r\n   (0.2ms)  BEGIN\r\n  SQL (0.3ms)  INSERT INTO `users_roles` (`role_id`, `user_id`) VALUES (1, 7)\r\n   (63.8ms)  ROLLBACK\r\n*NoMethodError: undefined method `name' for nil:NilClass*\r\nBut tables User and Role have column \"name\". My schema.rb\r\n\r\n  create_table \"users\", force: true do |t|\r\nt.string   \"email\",                                                  default: \"\",    null: false\r\nt.string   \"encrypted_password\",                                     default: \"\",    null: false\r\nt.string   \"reset_password_token\"\r\nt.datetime \"reset_password_sent_at\"\r\nt.datetime \"remember_created_at\"\r\nt.integer  \"sign_in_count\",                                          default: 0,     null: false\r\nt.datetime \"current_sign_in_at\"\r\nt.datetime \"last_sign_in_at\"\r\nt.string   \"current_sign_in_ip\"\r\nt.string   \"last_sign_in_ip\"\r\nt.datetime \"created_at\"\r\nt.datetime \"updated_at\"\r\nt.string   \"name\"\r\nt.string   \"mobile_phone\"\r\nt.integer  \"role\"\r\nt.decimal  \"internal_credit\",                precision: 8, scale: 2, default: 0.0,   null: false\r\nt.integer  \"web_sites_count\",                                        default: 0,     null: false\r\nt.integer  \"web_sites_visitors_today_count\",                         default: 0,     null: false\r\nt.boolean  \"blocked\",                                                default: false\r\nt.datetime \"deleted_at\"\r\n\r\n\r\n   add_index \"users\", [\"deleted_at\"], name: \"index_users_on_deleted_at\", using: :btree\r\n  add_index \"users\", [\"email\"], name: \"index_users_on_email\", unique: true, using: :btree\r\n  add_index \"users\", [\"reset_password_token\"], name: \"index_users_on_reset_password_token\", unique: true, using: :btree\r\n\r\n  create_table \"users_roles\", id: false, force: true do |t|\r\n    t.integer \"user_id\"\r\n    t.integer \"role_id\"\r\n  end\r\n\r\n  add_index \"users_roles\", [\"user_id\", \"role_id\"], name: \"index_users_roles_on_user_id_and_role_id\", using: :btree\r\n\r\n  create_table \"roles\", force: true do |t|\r\n    t.string   \"name\"\r\n    t.integer  \"resource_id\"\r\n    t.string   \"resource_type\"\r\n    t.datetime \"created_at\"\r\n    t.datetime \"updated_at\"\r\n  end\r\n\r\n  add_index \"roles\", [\"name\", \"resource_type\", \"resource_id\"], name: \"index_roles_on_name_and_resource_type_and_resource_id\", using: :btree\r\n  add_index \"roles\", [\"name\"], name: \"index_roles_on_name\", using: :btree\r\n\r\n  end\r\nHelp me please, guys."},"comment":{"url":"https://api.github.com/repos/RolifyCommunity/rolify/issues/comments/140555955","html_url":"https://github.com/RolifyCommunity/rolify/issues/331#issuecomment-140555955","issue_url":"https://api.github.com/repos/RolifyCommunity/rolify/issues/331","id":140555955,"user":{"login":"Aathi","id":5355180,"avatar_url":"https://avatars.githubusercontent.com/u/5355180?v=3","gravatar_id":"","url":"https://api.github.com/users/Aathi","html_url":"https://github.com/Aathi","followers_url":"https://api.github.com/users/Aathi/followers","following_url":"https://api.github.com/users/Aathi/following{/other_user}","gists_url":"https://api.github.com/users/Aathi/gists{/gist_id}","starred_url":"https://api.github.com/users/Aathi/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Aathi/subscriptions","organizations_url":"https://api.github.com/users/Aathi/orgs","repos_url":"https://api.github.com/users/Aathi/repos","events_url":"https://api.github.com/users/Aathi/events{/privacy}","received_events_url":"https://api.github.com/users/Aathi/received_events","type":"User","site_admin":false},"created_at":"2015-09-15T21:46:01Z","updated_at":"2015-09-15T21:46:01Z","body":"Getting same error message, I have tried what @andradei  suggested but no use\r\n<img width=\"1419\" alt=\"orumanam_ _ruby_ _202x50\" src=\"https://cloud.githubusercontent.com/assets/5355180/9891043/ca3d1d1c-5c03-11e5-8752-aa4d0eaf8b84.png\">\r\n"}}