{"action":"created","issue":{"url":"https://api.github.com/repos/fsek/web/issues/93","labels_url":"https://api.github.com/repos/fsek/web/issues/93/labels{/name}","comments_url":"https://api.github.com/repos/fsek/web/issues/93/comments","events_url":"https://api.github.com/repos/fsek/web/issues/93/events","html_url":"https://github.com/fsek/web/issues/93","id":63414134,"number":93,"title":"Use the bang methods save!, create!, update!, destroy!","user":{"login":"jforberg","id":1269005,"avatar_url":"https://avatars.githubusercontent.com/u/1269005?v=3","gravatar_id":"","url":"https://api.github.com/users/jforberg","html_url":"https://github.com/jforberg","followers_url":"https://api.github.com/users/jforberg/followers","following_url":"https://api.github.com/users/jforberg/following{/other_user}","gists_url":"https://api.github.com/users/jforberg/gists{/gist_id}","starred_url":"https://api.github.com/users/jforberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jforberg/subscriptions","organizations_url":"https://api.github.com/users/jforberg/orgs","repos_url":"https://api.github.com/users/jforberg/repos","events_url":"https://api.github.com/users/jforberg/events{/privacy}","received_events_url":"https://api.github.com/users/jforberg/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/fsek/web/labels/jforberg/rant","name":"jforberg/rant","color":"fad8c7"}],"state":"closed","locked":false,"assignee":null,"milestone":null,"comments":3,"created_at":"2015-03-21T14:52:09Z","updated_at":"2015-03-26T22:06:15Z","closed_at":"2015-03-26T17:20:29Z","body":"Always use the bang methods on AR objects unless you have a reason not to. Even then, use the bang methods.\r\n\r\nI found this code in master:\r\n\r\n```\r\nafter_create :create_profile_for_user\r\n\r\ndef create_profile_for_user\r\n  Profile.create(user: self)\r\nend\r\n```\r\n\r\nWhat does this do? It tries to create a profile, silently ignoring any validation errors and then throws away the reference to the only object that has information about the error. Not what you want.\r\n\r\nInstead, make it a habit to use the save!, create!, update!, destroy! methods and explicitly catch the exception if that is what you want to do. The exception you want is usually ```ActiveRecord::RecordInvalid```.\r\n\r\nOr just let the exception pass to the controller where ApplicationController will do the right thing automatically for you (as of branch cancan https://github.com/fsek/web/blob/cancan/app/controllers/application_controller.rb#L14)\r\n\r\nHave a nice day\r\n/Your friendy best-practices PSA guy"},"comment":{"url":"https://api.github.com/repos/fsek/web/issues/comments/86734643","html_url":"https://github.com/fsek/web/issues/93#issuecomment-86734643","issue_url":"https://api.github.com/repos/fsek/web/issues/93","id":86734643,"user":{"login":"jforberg","id":1269005,"avatar_url":"https://avatars.githubusercontent.com/u/1269005?v=3","gravatar_id":"","url":"https://api.github.com/users/jforberg","html_url":"https://github.com/jforberg","followers_url":"https://api.github.com/users/jforberg/followers","following_url":"https://api.github.com/users/jforberg/following{/other_user}","gists_url":"https://api.github.com/users/jforberg/gists{/gist_id}","starred_url":"https://api.github.com/users/jforberg/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/jforberg/subscriptions","organizations_url":"https://api.github.com/users/jforberg/orgs","repos_url":"https://api.github.com/users/jforberg/repos","events_url":"https://api.github.com/users/jforberg/events{/privacy}","received_events_url":"https://api.github.com/users/jforberg/received_events","type":"User","site_admin":false},"created_at":"2015-03-26T22:06:15Z","updated_at":"2015-03-26T22:06:15Z","body":"@davidwessman Activerecord has nothing to do with actions... Or what did you mean?"}}