【发布时间】:2016-02-13 00:57:04
【问题描述】:
给定以下表格
class EntryForm < Reform::Form
property :composition
property :native_language_version
validates :composition, presence: true
end
以及以下架构
create_table "entries", force: :cascade do |t|
t.text "composition"
t.text "native_language_version"
t.integer "language_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
end
以及下面的控制器代码
class EntriesController < ApplicationController
def new
@entry = EntryForm.new(Entry.new)
# @entry = Entry.new
end
end
以及simple_form的以下代码
= simple_form_for(@entry) do |f|
= f.input :composition
= f.input :native_language_version
= f.submit
我得到的不是composition 和native_language_version 的textarea,而是
<input class="string required form-control" type="text" name="entry[composition]" id="entry_composition">
改用 @entry = Entry.new 给了我一个 textarea 元素,这正是我想要的:
<textarea class="text optional form-control" name="entry[composition]" id="entry_composition"></textarea>
我尝试将type: :text 添加到EntryForm 中的:composition 属性,但没有帮助。
我也知道,我可以指定实际的输入类型,而不是使用 f.input,但这是一种 hack。
我如何将composition 是text 而不是string 到EntryForm 的事实传递给simple_form?
我正在使用 Rails 4.2.5.1、simple_form 3.2.1 和改革 2.1.0。
【问题讨论】:
标签: ruby-on-rails ruby-on-rails-4 simple-form reform