gpt4 book ai didi

ruby-on-rails - SimpleForm 不带 for(非模型表单)

转载 作者:行者123 更新时间:2023-12-03 05:20:19 27 4
gpt4 key购买 nike

是否可以在没有模型的情况下使用简单表单(由 Plataformatec 提供)?

https://github.com/plataformatec/simple_form

最佳答案

您可以使用 :symbol 作为第一个参数。

<%= simple_form_for :user, url: users_path do |f| %>
<%= f.input :name, as: :string %>
...
<% end %>

它会输出如下内容:

<form novalidate="novalidate" class="simple_form user" action="/users" accept-charset="UTF-8" method="post">
...
<div class="input string required user_name">
<label class="string required" for="user_name">
<abbr title="required">*</abbr> Name
</label>
<input class="string required" type="text" name="user[name]" id="user_name" />
</div>
...
</form>

关于ruby-on-rails - SimpleForm 不带 for(非模型表单),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5181143/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com