Skip to content

Instantly share code, notes, and snippets.

@cwoodcox
Created October 10, 2013 23:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cwoodcox/6927382 to your computer and use it in GitHub Desktop.
Save cwoodcox/6927382 to your computer and use it in GitHub Desktop.
# Create the associations for individual body_metrics and accept their nested
# attributes. This makes the biometrics form work and a few other things.
Dir['app/models/body_metric/*.rb'].collect { |file| File.basename(file).sub /\.rb/, '' }.each do |metric|
has_one :"current_#{metric}", -> { latest }, class_name: "BodyMetric::#{metric.camelize}"
accepts_nested_attributes_for :"current_#{metric}"
define_method("current_#{metric}") do
super() || self.send(:"build_current_#{metric}")
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment