我正在尝试将Evaluation
模型添加到我的Rails 4
应用中。Rails 4多态关联和关注
我制作了一个名为evaluation.rb
的模型。它具有:
evaluator
class Evaluation < ActiveRecord::Base
belongs_to :evaluator, :polymorphic => true
belongs_to :evaluatable, :polymorphic => true
我也让关注和evaluatable
为:
module Evaluator
extend ActiveSupport::Concern
included do
has_many :given_evaluations, as: :evaluator, dependent: :destroy, class_name: 'Evaluation'
end
end
module Evaluatable
extend ActiveSupport::Concern
included do
has_many :received_evaluations, as: :evaluatable, dependent: :destroy, class_name: 'Evaluation'
end
end
我已经包含在我的用户模型中的每个关注:
class User < ActiveRecord::Base
include Evaluator
include Evaluatable
在我的节目页,我想显示特定用户的评估(从其他用户(评估人员)接收)。
在我的节目,我有:
<% Evaluation.find(params[:id]).evaluations.order('created_at DESC').each do |eval| %>
<div id="portfolioFiltering" class="masonry-wrapper row">
<%= eval.remark %>
<%= eval.personal_score %>
<small><%= eval.created_at %></small>
在我的评价形式,我“不知道如何指定评估的收件人我已经基本形成,但我不清楚关于如何将它与谁应该接受评估用户
<%= simple_form_for(@evaluation) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.input :score, collection: 1..10, autofocus: true, :label => "How do you rate this experience (1 being did not meet expectations - 10 being met all expectations) ?" %>
<%= f.input :remark, as: :text, :label => "Evaluate your project experience", :input_html => {:rows => 10} %>
我的评价表有:
t.integer "user_id"
t.integer "evaluatable_id"
t.string "evaluatable_type"
t.integer "overall_score"
t.integer "project_score"
t.integer "personal_score"
t.text "remark"
t.boolean "work_again?"
t.boolean "continue_project?"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
add_index "evaluations", ["evaluatable_type", "evaluatable_id"], name: "index_evaluations_on_evaluatable_type_and_evaluatable_id", unique: true, using: :btree
问题
如何设置显示页面以显示用户收到的评估?
我该如何调整表格,使其指定用户ID作为应接受评估的人员?
伟大的问题,你很擅长解释你的问题..让我们看看是否有帮助 – illusionist
你打算使用'评估'评估用户以外的对象?根据你的回复,答案可以简化。 –
是的。我想评估用户做的项目 – Mel