【发布时间】:2012-10-24 15:30:56
【问题描述】:
我正在使用 rails 教程中的辅助方法,该方法将两个字符串连接在一起,以便在视图中的标题选择器中使用。它工作得很好,除非字符串中有撇号。
当 :group_name 包含撇号时,如下所示:
<title>The website | O&#x27;Malley Brothers</title>
方法如下:app/helpers/application_helper.rb
module ApplicationHelper
def full_title(page_title)
base_title = "Chicago Improv Festival"
if page_title.empty?
base_title
else
"#{base_title} | #{page_title}"
end
end
end
这是它在布局视图中的使用方式。 app/views/layouts/application.html.erb:
<title><%= full_title(yield(:title)) %></title>
这里是在另一个视图文件中设置 :title 的地方:app/views/submissions/show.html.erb
<% provide(:title, @submission.group_name) %>
【问题讨论】:
标签: ruby-on-rails string