dwilbank
dwilbank

Reputation: 2520

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?

Upvotes: 0

Views: 673

Answers (2)

Joel Brewer
Joel Brewer

Reputation: 1652

Why not just remove the erb tags?

<%= f.input :name, :input_html => { :value => @user.name } %>

Upvotes: 1

vee
vee

Reputation: 38645

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 %>

Upvotes: 1

Related Questions