Skip to content

Instantly share code, notes, and snippets.

@willsza
Last active August 28, 2015 00:08
Show Gist options
  • Save willsza/5017897ee66a33875b32 to your computer and use it in GitHub Desktop.
Save willsza/5017897ee66a33875b32 to your computer and use it in GitHub Desktop.
Select com simple_fields_for
.main-home
- @goals.each do |goal|
h1.text-center = goal.title
= simple_form_for goal do |f|
= f.error_notification
.form-group.text-center
= f.simple_fields_for :goal_options do |g|
= g.simple_fields_for :user_goal_options do |u|
= u.input :goal_option_id do
= g.select :goal_option_id
.form-group.text-center
= f.submit "Avançar", class: 'btn btn-success btn-lg'
hr
class Goal < ActiveRecord::Base
belongs_to :page
has_many :goal_options
validates :title, presence: true
accepts_nested_attributes_for :goal_options
end
class GoalOption < ActiveRecord::Base
belongs_to :goal
# Relacionamento muitos pra muitos com User
has_many :user_goal_options
has_many :users,
:through => :user_goal_options
accepts_nested_attributes_for :user_goal_options
end
class User < ActiveRecord::Base
has_many :answers
# Relacionamento muitos pra muitos com Goal
has_many :user_goal_options
has_many :goal_optons,
:through => :user_goal_options
end
class UserGoalOption < ActiveRecord::Base
belongs_to :user
belongs_to :goal_option
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment