Skip to content

Instantly share code, notes, and snippets.

@henkm
Created February 11, 2012 07:29
Show Gist options
  • Save henkm/1797434 to your computer and use it in GitHub Desktop.
Save henkm/1797434 to your computer and use it in GitHub Desktop.
# 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