[英]Ruby on Rails tutorial chapter 1.4.3 (part about bitbucket)
[英]about layouts in ruby on rails tutorial
我正在研究Ruby on Rails教程中的Ruby on Rails。 我做了测试,但是发现错误。 哪里错了?
test_should_get_home#StaticPagesControllerTest (1451158535.88s)
ActionView::Template::Error: ActionView::Template::Error: undefined method `full_title' for #<#<Class:0x007ff2da1e0bc0>:0x007ff2da1dbeb8>
app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb__2067729572228884173_70340508945500'
test/controllers/static_pages_controller_test.rb:9:in `block in <class:StaticPagesControllerTest>'
app/views/layouts/application.html.erb:4:in `_app_views_layouts_application_html_erb__2067729572228884173_70340508945500'
test/controllers/static_pages_controller_test.rb:9:in `block in <class:StaticPagesControllerTest>'
我不确定,但我认为您会遵循第3章测试标题
似乎尚未定义full_title
。
写吧
@full_title = "Ruby on Rails Tutorial Sample App"
希望这对您有帮助!
看起来方法full_title
尚未定义。
确保在app/helpers/application_helper.rb
正确定义了它。
这是我的app/helpers/application_helper.rb
文件:
module ApplicationHelper
def full_title(title="")
base_title = "Ruby on Rails Tutorial Sample App"
if title.blank?
base_title
else
"#{title} | #{base_title}"
end
end
end
并且不要忘记同时编辑app/views/layouts/application.html.erb
文件:
<head>
<title><%= full_title(yield(:title)) %></title>
<%= stylesheet_link_tag 'application', media: 'all',
'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
<%= render "layouts/shim" %>
</head>
根据full_title
方法的实现,它返回base_title
(即字符串Ruby on Rails Tutorial Sample App
)或"The title of your choice" | Ruby on Rails Tutorial Sample App
"The title of your choice" | Ruby on Rails Tutorial Sample App
如果您将标题作为方法的参数传递的话,可以通过在每个页面上放置<% provide :title, "your title here" %>
来实现)。
希望能帮助到你!
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.