Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/python-2.7/5.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Ruby on rails 在架构中添加列后,Simple_表单不发送值_Ruby On Rails_Simple Form - Fatal编程技术网

Ruby on rails 在架构中添加列后,Simple_表单不发送值

Ruby on rails 在架构中添加列后,Simple_表单不发送值,ruby-on-rails,simple-form,Ruby On Rails,Simple Form,我想用更多用户可以输入的值更新一个简单表单 为此,我: 1) 创建一个新的迁移,在我的数据库中添加新列。新的列apper是schema.db,因此我假设新的迁移工作正常 2) 在简单表单中添加链接到新列的“新”f.input 但是,一旦我提交了simple\u表单,新列的值不会传递到数据库,而旧列的值会被传递 new.html.erb <div class="container"> <div class="row "> <div class="col-

我想用更多用户可以输入的值更新一个
简单表单

为此,我:

1) 创建一个新的迁移,在我的数据库中添加新列。新的列apper是
schema.db
,因此我假设新的迁移工作正常

2) 在
简单表单
中添加链接到新列的“新”
f.input

但是,一旦我提交了
simple\u表单
,新列的值不会传递到数据库,而旧列的值会被传递

new.html.erb

<div class="container">

  <div class="row ">
    <div class="col-sm-6 col-sm-offset-3">

      <%= simple_form_for [@user, @project, @paper, @question], url: project_paper_questions_path do |f| %>
        <div class="form-inputs">

      <%= f.input :question_content_year, label: "1. Year"%>
      <%= f.input :question_content_country, label: "2. Country"%>
      <%= f.input :question_content_income, :collection =>[["Low income", -1], ["Middle income", 0], ["High income", 0.5]], label: "3. Income level" %>
      <%= f.input :question_content_type, :collection =>[["CUA", 0], ["CEA", 1], ["CBA", 2], ["CCA", 3], ["CMA", 4]], label: "4. Type of economic evaluation" %>
      <%= f.input :question_content_study, :collection =>[["RCT", 0], ["Quasi-experimental", 1], ["Modelling", 2], ["Observational", 3], ["Mixed RCT and Modelling", 4]], label: "5. Study Design " %>
      <%= f.input :question_content_modelling, :collection =>[["Decison Tree", 0], ["Markov model", 1], ["Patient level simulation/microsimulation", 2], ["Dynamic models", 3], ["Other", 4]], label: "6. Type of modeling, if modeling design " %>
      <%= f.input :question_content_perspective_a, :collection =>[["Social", 0], ["Provider/Health care system", 1], ["Program", 2], ["Patient", 3], ["Payer/Third party", 4], ["Mixed", 5]], label: "7. Perspective (as stated by authors)" %>
      <%= f.input :question_content_perspective_r, :collection =>[["Social", 0], ["Provider/Health care system", 1], ["Program", 2], ["Patient", 3], ["Payer/Third party", 4], ["Mixed", 5]], label: "8. Perspective (evaluated by reviewer)" %>
      <%= f.input :question_content_sensitivity, :collection =>[["One way/Univariate", 0], ["Multy-way/Multivariate", 1], ["Probabilistic analysis", 2], ["Not performaed/specified", 3], ["CMA", 4]], label: "9. Type of sensitivity analysis" %>
      <%= f.input :question_content_type, :collection =>[["<= 1", 0], ["1-10 years", 1], ["Over 10 years", 2], ["Not clearly stated", 3]], label: "10. Time horizon" %>
      <%= f.input :question_content_outcome, :collection =>[["QALY/DALY", 0], ["Natural units", 1], ["Process outcomes", 2], ["Monetary", 3]], label: "11. Outcome Measure" %>
      <%= f.input :question_content_intervention, label: "12. Decription of Intervention/Comparison" %>
      <%= f.input :question_content_data, :collection =>[["Primary", 0], ["Secondary", 1], ["Mixed", 2], ["Monetary", 3]], label: "13. Type and source of data used" %>
      <%= f.input :question_content_sample, label: "14. Sample Size" %>
      <%= f.input :question_content_description, label: "15. Description of analysis outcomes" %>



      **THE FOLLOWING ARE THE OLD QUESTIONS/COLUMNS AND THEY WORK


      <%= f.input :question_1, :collection =>["N/A", "No - 0", "Partially - 0.5", "Yes - 1"], label: "1. Identify the study as an economic evaluation" %>
      <%= f.input :question_2, :collection =>["N/A", "No - 0", "Partially - 0.5", "Yes - 1"], label: "2. Provide a structured summary of objectives, methods, results and conclusions" %>
      ...
      " %>
      <%= f.input :question_28, :collection =>["N/A", "No - 0", "Partially - 0.5", "Yes - 1"], label: "24. Describe any potential for conflict of interest among study contributors in accordance with journal policy.
      " %>


      <%= f.association :user, label: "Which user is creating it?", :as => :hidden, :input_html => { :value => current_user.id }  %>
      </div>


      <div class="form-actions">
        <%= f.button :submit, "Send your review" %>
      </div>
    </div>
    <% end %>
  </div>
  create_table "questions", force: :cascade do |t|
    t.bigint "user_id"
    t.bigint "paper_id"
    t.bigint "project_id"
    t.string "type"
    t.string "question_1"
    t.string "question_2"
    t.string "question_3"
    t.string "question_4"
...
    t.string "question_28"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false

THE FOLLOWING ARE THE COLUMNS I ADDED AND DO NOT WORK

    t.string "question_content_year"
    t.string "question_content_income"
    t.string "question_content_condensed_type"
    t.string "question_content_study"
    t.string "question_content_modelling"
    t.string "question_content_perspective_a"
    t.string "question_content_perspective_r"
    t.string "question_content_sensitivity"
    t.string "question_content_type"
    t.string "question_content_outcome"
    t.string "question_content_intervention"
    t.string "question_content_data"
    t.string "question_content_sample"
    t.string "question_content_description"
    t.string "question_content_country"
    t.index ["paper_id"], name: "index_questions_on_paper_id"
    t.index ["project_id"], name: "index_questions_on_project_id"
    t.index ["user_id"], name: "index_questions_on_user_id"
  end
控制器

  def new
    @project = Project.find(params[:project_id])
    @paper = Paper.find(params[:paper_id])
    @question = Question.new
  end

  def create
    @question = Question.new(question_params)
    @question.project = Project.find(params[:project_id])
    @question.paper = Paper.find(params[:paper_id])
    if @question.save
      redirect_to projects_path
    else
      flash[:alert] = "Some error !"
      render :new
    end
  end
只有旧值(从
问题1
问题28
被发送到数据库,而新值-例如:
:问题内容年
未通过)。 如果我使用
rails控制台检查
-->
问题。最后一个
-->新列的值为
nil


我认为问题在于您没有修改控制器中的
question\u params
方法。您需要在那里的
permit
调用中列出新字段


此许可机制的目的是将您希望随表单一起提交的属性列为白名单,以便恶意创建的表单提交不能覆盖不应该从该表单更新的字段。

请您在控制器中显示
question\u params
方法的代码,谢谢您的评论。下面的答案解决了我的问题。我犯了一个非常愚蠢的错误。