[英]How to use a ruby variable as the default value in simple_form?
Good sirs: 好先生:
I have this 我有这个
<%= f.input :name, :input_html => { :value => '<%= @user.name %>' } %>
and the erb tags within erb tags brings joy to no one. erb标签中的erb标签给所有人带来欢乐。
How to do it correctly? 如何正确做?
Use it as value: @user.name
: 将其用作value: @user.name
:
<%= f.input :name, :input_html => { :value => @user.name } %>
If the form builder object f
in your case is for the @user
instance then the value will be pre-populated in case of validation errors. 如果您的情况下的表单构建器对象f
用于@user
实例,则在验证错误的情况下将预先填充该值。 For example, the following will suffice: 例如,满足以下条件:
<%= simple_form_for @user do |f| %>
<%= f.input :name %>
<% end %>
为什么不删除erb标签呢?
<%= f.input :name, :input_html => { :value => @user.name } %>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.