Как добавить новое поле в форму Rails? - PullRequest
0 голосов
/ 07 июня 2019

Я пытаюсь добавить новое поле в форму с помощью Rails. В каждом поле должен быть раскрывающийся список параметров доставки со значением: shipping_option_id:

Как мне сделать это с формой?

Схема

 create_table "products", force: :cascade do |t|
    t.string "sku"
    t.string "name"
    t.datetime "created_at", null: false
    t.datetime "updated_at", null: false
    t.bigint "shipping_option_id"
    t.bigint "product_region_id"
    t.index ["product_region_id"], name: "index_products_on_product_region_id"
    t.index ["shipping_option_id"], name: "index_products_on_shipping_option_id"
    t.index ["sku"], name: "index_products_on_sku", unique: true
  end

1 Ответ

0 голосов
/ 07 июня 2019

Вы также можете использовать помощник options_for_select, чтобы добавить значения из данной модели в ваш select_tag

<%= select_tag 'shipping_option_id', options_for_select(@your_model.collect{ |o| [o.name, o.id] }) %>

Источник: https://apidock.com/rails/ActionView/Helpers/FormTagHelper/select_tag

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...