尝试高亮显示轨道中的标头时出现NoMethodError



我是Rails的初学者,我正在开发电影数据库应用程序,当我点击它时,很难突出显示这个标题。

下面是我的视图目录,使用haml。

%table#movies
  %thead
    %tr
      %th{ :class => hilite('title')}= link_to "Movie Title", movies_path(:sort => 'title'), :id => "title_header"
      %th Rating
      %th{ :class => hilite('release_date')}= link_to "Release Date", movies_path(:sort => 'release_date'), :id => "release_date_header"
      %th More Info

然后我的application.css文件中有以下内容。

table#movies hilite {
  background-color: yellow;
} 

当我通过cloud9在localhost服务器上运行它时,我得到了以下错误。

NoMethodError in Movies#index
undefined method `hilite' for #<#<Class:0x00000003500fe8>:0x007f1afc229520>

如有任何协助,我们将不胜感激!

我对HAML不是很熟悉,但看看教程网站中的一些示例用法,我想我可能知道问题是什么。目前,你有这个:

%th{ :class => hilite('title')}= link_to "Movie Title", movies_path(:sort => 'title'), :id => "title_header"

然而,hilite不是一种方法。这只是你想在CSS文件中使用的类名,所以你应该为此更改它:

%th{ :class => "hilite" }= link_to "Movie Title", movies_path(:sort => 'title'), :id => "title_header"

此外,为了给您省去一点麻烦,我注意到您在CSS:中错过了一个.

table#movies .hilite {
  background-color: yellow;
} 

如果这是你想要的,请告诉我。干杯

最新更新