0

I have used html.erb template in Rails to passing some value for HTML input and my source code looks like this:

   <% all = "All value" %>
   <input type="text" name="name" id="name" value=<%= all %>>

But when the view is rendered, it seems like a string after space was missing and I just got:

<input type="text" name="name" id="name" value="All">

But my expection is:

<input type="text" name="name" id="name" value="All value">

I appreciate any help!

Ninh Le
  • 1,291
  • 7
  • 13
  • 2
    You're not quoting it, so normal HTML parsing rules apply. – Dave Newton Mar 19 '20 at 15:06
  • You can also just use the [Rails helpers](https://api.rubyonrails.org/v6.0.2.1/classes/ActionView/Helpers/FormTagHelper.html#method-i-text_field_tag) instead of slumming it `<%= text_field_tag(:name, all) %>`. – max Mar 19 '20 at 15:47
  • Thanks for your help! – Ninh Le Mar 19 '20 at 16:15

1 Answers1

1

Quote your all variable like this:

<input type="text" name="name" id="name" value="<%= all %>">
Sohail Aslam
  • 727
  • 4
  • 24
  • 2
    ... It is already a string. There's no "or"--property values must be quoted if there's anything that will have HTML parsing applied. – Dave Newton Mar 19 '20 at 15:06