Simple_form架构中添加列后不发送值

问题描述 投票:1回答:1

我想更新simple_form与多个值,用户可以输入。

为了做到这一点我:

1)创建一个新的迁移我的数据库questions新列添加。新列冲击片雷管是schema.db,所以我认为新的迁移工作。

2)添加在simple_form,“新” f.input链接到新的列。

但是,一旦我提交simple_form,新列的值不会传递到数据库中,而旧的传递。

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>

schema.db

  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

只有旧值( - :question_1不会传递例如从question_28:question_content_year被发送到数据库中,而新建一个)。如果,如果我请与rails console - > Question.last - >新列具有nil的价值。

Nil value for the columns I added The values of the new columns are not sent

ruby-on-rails simple-form
1个回答
2
投票

我认为这个问题是你没有修改您的控制器的question_params方法。你需要列出在permit通话有新的领域。

本许可证机制的目的是为了白名单属性,您希望与形式提交,这样一个恶意制作的表格提交无法覆盖那些不应该从形式更新的字段。

© www.soinside.com 2019 - 2024. All rights reserved.