user7518095
user7518095

Reputation: 93

String Manipulation in Embedded Ruby

So I have embedded Ruby in HTML, and I need to declare a new variable which will be a manipulated version of the old variable. For instance, in

<%= newfood = food%>

if food = "AB&CSoup", I'd want the string to become "ABCSoup". After declaring the new variable in embedded ruby brackets, how can I remove the ampersand?

Upvotes: 1

Views: 122

Answers (2)

Alejandro Montilla
Alejandro Montilla

Reputation: 2654

Try with delete method

<%= newfood = food.delete('&') %>

Upvotes: 0

Sajin
Sajin

Reputation: 1638

<% newfood = food %>
<% newfood.gsub!('&','') %>

Upvotes: 1

Related Questions