Question

user_relation.rb

 14 class UserRelation < ActiveRecord::Base
 15   belongs_to :user
 16   belongs_to :with_user, :class_name => "User", :foreign_key => :with_user_id
 17   belongs_to :group
 18   has_many :evaluations
 19   has_many :ratings, :through => :evaluations
 20   has_many :user_relation_skills  
 21   has_many :user_relation_skills_in_progress, -> { where state: "in_progress" }, class_name: 'UserRelationSkill' 
 22   alias_method :skills, :user_relation_skills
 23 
 24   has_many :progresses, :through => :skills

user_relation_skill.rb

 13 class UserRelationSkill < ActiveRecord::Base
 14   belongs_to :skill
 15   belongs_to :user_relation
 16   has_many :progresses
 17   has_many :ratings, :as => :scope
 18   has_many :videos, :class_name => "Video", :as => :viewable
 19 
 20   accepts_nested_attributes_for :ratings, :progresses
 21 
 22   accepts_nested_attributes_for :videos, :allow_destroy => true

rating.rb

 19 class Rating < ActiveRecord::Base
 20   belongs_to :scope, :polymorphic => true
 21   belongs_to :ratable, :polymorphic => true
 22   belongs_to :rater, :class_name => "User"
 23   belongs_to :evaluation

_form.html.erb

 17 <%= form_for(@user_relation) do |f| %>
 18     <%= f.fields_for :user_relation_skill do |ff| %> 
 19         <%= ff.select(:rating, options_for_select(
 20             (1..8),
 21             (ff.rating.try(:value) || 0))) %>   
 22     <% end%>
 23 <% end%>

@user_relation.first.user_relation_skills.first.ratings.first.value pulls the data I want I'm just curious how I can get this into a form so I can update and edit the values with a submit button

currently the form_for code just returns a

undefined method `rating'
(ff.rating.try(:value) || 0))) %> 
Was it helpful?

Solution

I believe you need to use ff.object.rating instead of ff.rating

That should at least pull a value for you from ff, but I'm not 100% how you're creating that select, so that might not be the only thing needed to solve your problem.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top