Say I have a hidden field inside a form which tells me which quote
character some file uses. The details are irrelevant, but I need to have a
string value that could have a double quote. Assume we have a variable
@quote_char = '"'
Now, in the view, I try all of these
<input type='hidden' name='quote_char' value=<%=
html_escape(@quote_char) %> >
<input type='hidden' name='quote_char' value="<%=
html_escape(@quote_char) %>" >
<input type='hidden' name='quote_char' value="<%= @quote_char %>" >
<input type='hidden' name='quote_char' value=<%= @quote_char.inspect %>
>
<%= hidden_field_tag :quote_char, @quote_char %>
None of these give well-formed HTML that was interpreted correctly by the
browser. The only one that seemed to work was
<input type='hidden' name='quote_char' value=<%=
html_escape(@quote_char).inspect %> >
which gave
<input type='hidden' name='quote_char' value=""" >
So what exectly is the correct way to handle strings possibly containing
quotes in views. Obviously the string may or may not contain said quotes
every time the view is generated so there should be a general way to handle
this with some helper function, etc.
Thanks!
--
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msg/rubyonrails-talk/-/LanotYBTLPgJ.
For more options, visit https://groups.google.com/groups/opt_out.