Last active
December 28, 2015 21:49
-
-
Save karellm/7567144 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
= form_for(@visualization) do |f| | |
= f.input :title | |
= f.fields_for :inputs_visualizations do |iv| | |
= iv.input :color | |
= iv.fields_for :input do |i| | |
= i.input :title | |
= f.button :submit, "Save" |
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
class Input < ActiveRecord::Base | |
# Associations ------------------ | |
has_many :inputs_visualizations, dependent: :destroy, order: "inputs_visualizations.order ASC" | |
has_many :visualizations, through: :inputs_visualizations | |
# Attributes -------------------- | |
attr_accessible :title, :unit | |
end |
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
class InputsVisualization < ActiveRecord::Base | |
# Associations ------------------ | |
belongs_to :input | |
belongs_to :visualization | |
# Attributes -------------------- | |
attr_accessible :input_id, :visualization_id, :color, :input_attributes | |
accepts_nested_attributes_for :input, :reject_if => lambda { |i| i[:title].blank? }, :allow_destroy => true | |
end |
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
class Visualization < ActiveRecord::Base | |
# Associations ------------------ | |
has_many :inputs_visualizations, dependent: :destroy, order: "inputs_visualizations.order ASC" | |
has_many :inputs, through: :inputs_visualizations, order: "inputs_visualizations.order ASC" | |
# Attributes -------------------- | |
attr_accessible :title, :inputs_visualizations_attributes | |
accepts_nested_attributes_for :inputs_visualizations, :reject_if => lambda { |a| a[:input_id].blank? }, :allow_destroy => true | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment