Skip to content

Instantly share code, notes, and snippets.

@dougalcorn
Forked from mguterl/gist:641041
Created October 22, 2010 18:15
Show Gist options
  • Save dougalcorn/641080 to your computer and use it in GitHub Desktop.
Save dougalcorn/641080 to your computer and use it in GitHub Desktop.
class User < ActiveRecord::Base
has_one :candidate_profile
alias_method :candidate_profile_without_initialization :candidate_profile
def candidate_profile
candidate_profile_withough_intitialization || build_candidate_profile
end
end
user = User.last
user.candidate_profile # => super: no superclass method `candidate_profile' for #<User:0x10c639a90>
@jimweirich
Copy link

Just tried this in a simple rails app. This approach seems to work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment