未知属性' gradework'反馈

时间:2017-05-03 00:58:59

标签: ruby-on-rails ruby

我有以下错误:

  

"致敬'成绩'反馈。"

链接是rails控制台的屏幕,发送的参数是:

"{" feedback "=> {" anotations "=>" Holiiii "," score "=>" 12 " 1 "," user "=>" # <User: 0x007f4674123f38> "}}"

错误图片:

Error Image

feedback.rb

class CreateFeedbacks < ActiveRecord::Migration[5.0]
   def change
     create_table :feedbacks do |t|
       t.text :anotations
       t.integer :score
       t.references :gradework, foreign_key: true
       t.references :user, foreign_key: true
       t.timestamps
     end
   end
end

schema.rb

create_table "feedbacks", force: :cascade do |t|
    t.text     "anotations"
    t.integer  "score"
    t.integer  "gradework_id"
    t.integer  "user_id"
    t.datetime "created_at",   null: false
    t.datetime "updated_at",   null: false
    t.index ["gradework_id"], name: "index_feedbacks_on_gradework_id", using: :btree
    t.index ["user_id"], name: "index_feedbacks_on_user_id", using: :btree
  end

create_table "gradeworks", force: :cascade do |t|
    t.string   "name"
    t.text     "description"
    t.string   "status"
    t.date     "delivery_date"
    t.date     "begin_date"
    t.time     "hour"
    t.text     "locale"
    t.string   "semester"
    t.datetime "created_at",    null: false
    t.datetime "updated_at",    null: false
    t.string   "file"
  end

feedbackController:

def create
     @feedback = Feedback.new(feedback_params)
    respond_to do |format|
      if @feedback.save!
        format.html { redirect_to @feedback, notice: 'Feedback was successfully created.' }
        format.json { render :show, status: :created, location: @feedback }
      else
        format.html { render :new, notice: 'Feedback was not created.' }
        format.json { render json: @feedback.errors, status: :unprocessable_entity }
      end
    end
  end   

def feedback_params
      params.require(:feedback).permit(:anotations, :score, :gradework, :user)
    end

视图:

<form role="form" id="newForm" action="/feedbacks" method="post">

      <div class="form-group">        
          Comentario:<br>
          <textarea  type="text" rows="5" class="form-control"
             id="inputAnotations" placeholder="Ingrese su comentario"                                                    name="feedback[anotations]" required></textarea>
        <br><br>
      </div>
      <div class="form-group">
                Score:<br>
                <input type="number" class="form-control" name="feedback[score]">
     </div>
     <div class="form-group">
            <label for="gradework">Tesis:</label>
             <%= select_tag(:gradework, options_from_collection_for_select(@grad_jury ,:id, :name), :prompt => "Ninguno", class: "form-control", name: "feedback[gradework]") %>
     </div>
     <div class="form-group">
            <%#User:<br>%>
            <input type="hidden" class="form-control" name="feedback[user]" value= <%= @cUser %>>
    </div>

      <br><br>
    <button type="submit" class="btn btn-default" data-dismiss="">Agregar</button>
    <!-- <input type="submit" value="Agregar"> -->
</form>

我不知道出了什么问题!

2 个答案:

答案 0 :(得分:0)

您应该有两件事来创建成绩单条目以及您的观点中的反馈条目:

    C模型中
  1. None (CMAKE_C_FLAGS or CMAKE_CXX_FLAGS used) Debug (CMAKE_C_FLAGS_DEBUG or CMAKE_CXX_FLAGS_DEBUG) Release (CMAKE_C_FLAGS_RELEASE or CMAKE_CXX_FLAGS_RELEASE) RelWithDebInfo (CMAKE_C_FLAGS_RELWITHDEBINFO or CMAKE_CXX_FLAGS_RELWITHDEBINFO MinSizeRel (CMAKE_C_FLAGS_MINSIZEREL or CMAKE_CXX_FLAGS_MINSIZEREL)
  2. 表单中的名称应为belongs_to :gradework,而不是Feedback

答案 1 :(得分:0)

问题似乎在这里:

<%= select_tag(:gradework, options_from_collection_for_select(@grad_jury ,:id, :name), :prompt => "Ninguno", class: "form-control", name: "feedback[gradework]") %>

您的表单正在发送不在您的模型中的gradework属性(Feedback),因此您需要发送gradework_id,所以请尝试将以上行转换为此:< / p>

<%= select_tag(:gradework_id, options_from_collection_for_select(@grad_jury ,:id, :name), :prompt => "Ninguno", class: "form-control", name: "feedback[gradework_id]") %>

这会将gradework_id作为参数发送,并在select中选择任何值。