我是ruby on rails的新手。 我最近手动将我的erb文件转换为haml文件。我现在面临一个奇怪的问题。我有两个控制器和几个视图。主页正确显示布局,但其他视图不显示。我正在尝试使用“application.html.haml”进行布局(默认选中)。
当我将标签添加到视图时,一切正常。但是,我不应该这样做,对吗?
application.html.haml
!!! 5
%html
%head
%title XYZ
= stylesheet_link_tag "application", :media => "all"
= javascript_include_tag "application"
= csrf_meta_tags
%body
= yield
my_controller.rb
require 'somefile'
class MyController < ApplicationController
def initialize
@information = Information.new # inside models folder
end
def fetch_information
input = params[:search]
input = input.strip
flash[:error] = nil
@hosts = @information.host(input)
if @hosts.count == 0
flash[:error] = "N/A: #{input}!"
else
# add to cookies
end
end
end
答案 0 :(得分:0)
发现问题!这是因为我没有在我的控制器的super
方法中调用initialize
。