I developed Rails app.
Characters such as &
are escaped to &
in <title>
tag.
For example,foo & bar
is displayed such as foo & bar
in the title.
When I use raw
, it can be displayed as I expect. But I don't want to use raw
because the data will be inputted by the user.
I'd like to display like this post (Pls see only title. Contents is nothing to do with my question). &
is displayed in the title in spite of inputted by the user.
My code is as below.
application.html.erb
<head>
<title><%= full_title(yield(:title)) %></title>
...
application_helper.rb
def full_title(page_title = '')
base_title = "app name"
if page_title.empty?
base_title
else
page_title + " | " + base_title
end
end
I added provide
in some view files, such as show.html.erb.
<% provide(:title, @schedule.title) %> #this title is inputted by user
Is it possible to escape it, but allow some characters unescaped?