사용자가 다른 사용자에게 의견을 남길 수 있도록 레일 평가 모델을 설정하는 방법을 파악하는 데 어려움이 있습니다.레일 - 연관성, 사용자 의견 - 사용자 의견 - 피드백 표시
User.rb
을 :Rails - feedback on specific users, how to set up the form to identify relevant users
내가 그로부터받은 제안은 다음과 같이 모델을 설정했다 :
은이 게시물에서 내 문제의 핵심을 요약has_many :given_evaluations, foreign_key: :evaluator_id, dependent: :destroy, class_name: Evaluation
has_many :received_evaluations, foreign_key: :evaluatee_id, dependent: :destroy, class_name: Evaluation
evaluation.rb
,210평가 컨트롤러
class EvaluationsController < ApplicationController
before_action :set_evaluation, only: [:show, :edit, :update, :destroy]
# before_filter :get_user, only: [:show, :edit, :update, :destroy]
# GET /evaluations
# GET /evaluations.json
def index
# @evaluations = Evaluation.all
@given_evaluations = current_user.given_evaluations
@received_evaluations = current_user.received_evaluations
end
# GET /evaluations/1
# GET /evaluations/1.json
def show
# @received_evaluations = @user.received_evaluations
@evaluation = current_user.received_evaluations.find_by(id: params[:id]) || current_user.given_evaluations.find(params[:id])
# @received_evaluation = current_user.received_evaluations.find params[:id]
end
# GET /evaluations/new
def new
@evaluation = Evaluation.new
end
# GET /evaluations/1/edit
def edit
end
# POST /evaluations
# POST /evaluations.json
def create
# @evaluation = Evaluation.new(evaluation_params)
@evaluation = current_user.given_evaluations.build(evaluation_params)
respond_to do |format|
if @evaluation.save
format.html { redirect_to @evaluation, notice: 'Evaluation was successfully created.' }
format.json { render :show, status: :created, location: @evaluation }
else
format.html { render :new }
format.json { render json: @evaluation.errors, status: :unprocessable_entity }
end
end
end
# PATCH/PUT /evaluations/1
# PATCH/PUT /evaluations/1.json
def update
current_user.given_evaluations.find(params[:id])
respond_to do |format|
if @evaluation.update(evaluation_params)
format.html { redirect_to @evaluation, notice: 'Evaluation was successfully updated.' }
format.json { render :show, status: :ok, location: @evaluation }
else
format.html { render :edit }
format.json { render json: @evaluation.errors, status: :unprocessable_entity }
end
end
end
# DELETE /evaluations/1
# DELETE /evaluations/1.json
def destroy
current_user.given_evaluations.find(params[:id])
@evaluation.destroy
respond_to do |format|
format.html { redirect_to evaluations_url, notice: 'Evaluation was successfully destroyed.' }
format.json { head :no_content }
end
end
private
# Use callbacks to share common setup or constraints between actions.
def set_evaluation
@evaluation = Evaluation.find(params[:id])
end
# Never trust parameters from the scary internet, only allow the white list through.
def evaluation_params
params[:evaluation].permit(:overall_score, :project_score, :personal_score, :remark, :work_again?, :continue_project?, :evaluatee_id)
end
end
평가서
<%= simple_form_for(@evaluation) do |f| %>
<%= f.error_notification %>
<div class="form-inputs">
<%= f.select :evaluatee_id, User.all.map{|u| [u.formal_name, u.id]} %>
<%= f.input :overall_score, collection: 1..10, autofocus: true, :label => "How do you rate this project experience (1 being did not meet expectations - 10 being met all expectations) ?" %>
<%= f.input :continue_project?, as: :boolean, checked_value: true, unchecked_value: false, :label => "Do you intend to continue working on the project?" %>
<%= f.input :remark, as: :text, :label => "Evaluate your experience", :input_html => {:rows => 10} %>
</div>
<div class="form-actions">
<%= f.button :submit %>
평가보기 표시
<% @received_evaluations.each do |receval| %>
<div id="portfolioFiltering" class="masonry-wrapper row">
<%= receval.remark %>
<%#= eval.personal_score %>
<small><%= receval.created_at %></small>
</div>
<% end %>
평가 뷰 표시에서
대체 시도
<% @given_evaluations.each do |receval| %>
<div id="portfolioFiltering" class="masonry-wrapper row">
<%= receval.remark %>
<%#= eval.personal_score %>
<small><%= receval.created_at %></small>
</div>
<% end %>
지금 데 문제는 관계없이 나는 쇼에 주어진 평가 또는 수신 평가를 게재하도록 노력 여부, I라는 오류 메시지가 얻을 수 있다는 것입니다
:
undefined method `each' for nil:NilClass
내가 방법을 알아낼 수 없습니다를 사용자가 다른 사용자를 평가할 수 있도록 모델을 설정합니다. 나는 각 사용자가받은 평가를 각각의 쇼 페이지에 보여주고 싶다. 나는 무엇이 잘못되었는지 알 수 없다. 콘솔에서 사용자가 다음과 같은 평가를 받았음을 알 수 있습니다.
=> #<Evaluation id: 8, evaluatee_id: 34, overall_score: 4, project_score: 5, personal_score: 5, remark: "jhjkhjhjkhkjhjkhjhkhjhkj", work_again?: nil, continue_project?: nil, created_at: "2016-06-12 21:52:53", updated_at: "2016-06-12 21:52:53", evaluator_id: 34>
내가 작업하고있는 사용자의 항목이 있습니다. 그러나, 나는 그 평가를 보여주는 방법을 찾을 수 없습니다. @given_evaluations
및 @received_evaluations
쇼 작업에 설정되지 않는 및 주석 부분이 있으므로 이유는 없었던 하나 개의 인스턴스를 반환 할 것 ActiveRecord#find
방법을 사용하고 있습니다 : 내가 볼 수