Created
February 11, 2012 07:29
-
-
Save henkm/1797434 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# models/user.rb | |
class User < ActiveRecord::Base | |
def self.current | |
Thread.current[:user] | |
end | |
def self.current=(user) | |
Thread.current[:user] = user | |
end | |
end | |
#controllers/application_controller.rb | |
class ApplicationController < ActionController::Base | |
def set_current_user | |
User.current = current_user | |
end | |
end | |
# in de controller van hond-ouder relaties in de actie waarin je de honden opslaat (update, create) | |
def update (en/of: def create) | |
... | |
User.current = current_user | |
... | |
end | |
# models/dog.rb | |
before_save :set_user | |
def set_user | |
self.user_id = User.current.id | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment