Я хотел обновить simple_form
, добавив больше значений, которые пользователь может ввести.
Для этого я:
1) Создать новую миграцию, добавив в мою базу данных questions
новые столбцы.Новый столбец apper - 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
.