简体   繁体   中英

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.

How to do it correctly?

Use it as 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. 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 } %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM