Ruby 我有一个深度嵌套的关系,我想创建一个表单来访问不同的部分
用户关系.rbRuby 我有一个深度嵌套的关系,我想创建一个表单来访问不同的部分,ruby,activerecord,ruby-on-rails-4,activeview,Ruby,Activerecord,Ruby On Rails 4,Activeview,用户关系.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, :throug
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
我认为您需要使用
ff.object.rating
而不是ff.rating
这至少可以为您从ff中提取一个值,但我不是100%地了解您是如何创建选择的,因此这可能不是解决问题所需的唯一方法 谢谢,我错过了那个东西
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
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
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%>
undefined method `rating'
(ff.rating.try(:value) || 0))) %>