Ruby on rails Rails-复选框未变为true

Ruby on rails Rails-复选框未变为true,ruby-on-rails,Ruby On Rails,我在Rails项目中添加了一个复选框。当用户在创建一本书时标记tradeablestatus时,它应该写为true,但无论如何都是false books/_form.html.erb <%= form_with(model: book, local: true) do |form| %> <% if book.errors.any? %> <div id="error_explanation"> <h2>

我在Rails项目中添加了一个复选框。当用户在创建一本书时标记tradeablestatus时,它应该写为true,但无论如何都是false

books/_form.html.erb

<%= form_with(model: book, local: true) do |form| %>
  <% if book.errors.any? %>
    <div id="error_explanation">
      <h2><%= pluralize(book.errors.count, "error") %> prohibited this book from being saved:</h2>

      <ul>
        <% book.errors.full_messages.each do |message| %>
          <li><%= message %></li>
        <% end %>
      </ul>
    </div>
  <% end %>
  <p> If you want your book to be available, tick the status and if you want your book to be tradeable, tick the tradeablestatus. </p>
  <div class="field">
    <%= form.label :title %>
    <%= form.text_field :title %>
  </div>

  <div class="field">
    <%= form.label :author %>
    <%= form.text_field :author %>
  </div>

  <div class="field">
    <%= form.label :pagecount %>
    <%= form.number_field :pagecount %>
  </div>

  <div class="field">
    <%= form.label :status %>
    <%= form.check_box :status %>
  </div>

    <div class="field">
    <%= form.label :tradeablestatus %>
    <%= form.check_box :tradeablestatus %>
  </div>

  <div class="actions">
    <%= form.submit %>
  </div>
<% end %>

您好)实际上我要做的是通过键入
rails g migration AddTradeableStatusToBooks tradeablestatus:boolean生成一个复选框,并将该复选框放入_form.html.erb。以form.check_框的形式。通常,当我创建模型时,我输入status:boolean,它工作正常,但没有发生。我意识到我忘了添加与tradeablestatus相关的参数。很抱歉占用了您的时间。@CENGICCMATARACI(没问题),因为我认为您忘了添加它)
class AddTradeableStatusToBooks < ActiveRecord::Migration[6.0]
  def change
    add_column :books, :tradeablestatus, :boolean
  end
end
ActiveRecord::Schema.define(version: 2020_10_28_092816) do

  # These are extensions that must be enabled in order to support this database
  enable_extension "plpgsql"

  create_table "books", force: :cascade do |t|
    t.string "title"
    t.string "author"
    t.integer "pagecount"
    t.boolean "status"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.integer "user_id"
    t.string "username"
    t.boolean "tradeablestatus", default: false, null: false
  end

  create_table "comments", force: :cascade do |t|
    t.string "title"
    t.string "content"
    t.bigint "user_id", null: false
    t.bigint "book_id", null: false
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.boolean "status", default: false, null: false
    t.index ["book_id"], name: "index_comments_on_book_id"
    t.index ["user_id"], name: "index_comments_on_user_id"
  end

  create_table "users", force: :cascade do |t|
    t.string "email", default: "", null: false
    t.string "encrypted_password", default: "", null: false
    t.string "reset_password_token"
    t.datetime "reset_password_sent_at"
    t.datetime "remember_created_at"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.string "username"
    t.index ["email"], name: "index_users_on_email", unique: true
    t.index ["reset_password_token"], name: "index_users_on_reset_password_token", unique: true
  end

  add_foreign_key "comments", "books"
  add_foreign_key "comments", "users"
end