我有一个轨道项目。
在application.html.slim
我有:
doctype html
html
head
title RailsMongoidPj
= stylesheet_link_tag "application", media: "all", "data-turbolinks-track" => true
= javascript_include_tag "application", "data-turbolinks-track" => true
= csrf_meta_tags
meta content="width=device-width, initial-scale=1.0" name="viewport"
= yield(:html_head)
body
= yield
在具有方法的控制器SearchController
中:
def javascript(*files)
content_for(:html_head) do
javascript_include_tag(*files)
end
end
helper_method :javascript
此控制器还有一个new
带有相应视图的方法,其内容是:
= javascript('/vendor/assets/javascript/handelbars.runtime.js')
- content_for :html_head do
script#entry-template type="text/x-handlebars-template"
| template content
但我有一个错误:
undefined method `content_for' for #<SearchFlickrController:0x007f8e4f2bae78>
Extracted source (around line #3):
1 / search flickr api page
2
3 = javascript('/vendor/assets/javascript/handelbars.runtime.js')
4
5 - content_for :html_head do
6 script#entry-template type="text/x-handlebars-template"
为什么方法content_for
未定义?这不是标准rails
方法吗?