Ryan King
Ryan King

Reputation: 3696

Rails gsub not working in view

I have the following code in my view, I don't understand why the gsub doesn't work.

<div class="section" id="<%= section.title.gsub(/_/, ' ') %>">

When .title = "Test Title" it just returns "Test Title" rather than "Test_Title"

What's going wrong here?

Upvotes: 0

Views: 395

Answers (1)

Zippie
Zippie

Reputation: 6088

It should be the other way around:

"Test Title".gsub(/ /, '_') #=> "Test_Title"

Upvotes: 2

Related Questions