Ruby on rails 3.2 style.css.erb预编译资产提供了未定义的方法“[]';对于nil:NilClass错误

Ruby on rails 3.2 style.css.erb预编译资产提供了未定义的方法“[]';对于nil:NilClass错误,ruby-on-rails-3.2,asset-pipeline,Ruby On Rails 3.2,Asset Pipeline,我在rails应用程序的stylesheets文件夹中为字体创建了一个文件 @font-face { font-family: 'MuseoSans500'; src: url("<%= asset_path('museosans_500-webfont.eot?')%>") format('embedded-opentype'); font-weight: normal; font-style: normal; } @font-face { font-family:

我在rails应用程序的stylesheets文件夹中为字体创建了一个文件

@font-face {
 font-family: 'MuseoSans500';
 src: url("<%= asset_path('museosans_500-webfont.eot?')%>") format('embedded-opentype');
 font-weight: normal;
 font-style: normal;
 }

@font-face {
 font-family: 'MuseoSans500';
 src: url("<%= asset_path('museosans_500-webfont.woff')%>") format('woff'),
   url("<%= asset_path('museosans_500-webfont.ttf')%>") format('truetype'),
   url("<%= asset_path('museosans_500-webfont.svg#MuseoSans500')%>") format('svg');
font-weight: normal;
font-style: normal;
}

(在/home/hbror/applications/survey/app/assets/stylesheets/application.css中)

您应该将字体放在新的资产目录中,例如
app/assets/fonts
,并通过将其放在
应用程序.rb
中将其包括在资产目录中:

# Add the fonts path
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')

# Precompile additional assets
config.assets.precompile += %w( .svg .eot .woff .ttf )
#添加字体路径

config.assets.path您应该将字体放在新的资产目录中,例如
app/assets/fonts
,并通过将其放在
应用程序.rb
中将其包括在资产目录中:

# Add the fonts path
config.assets.paths << Rails.root.join('app', 'assets', 'fonts')

# Precompile additional assets
config.assets.precompile += %w( .svg .eot .woff .ttf )
#添加字体路径

config.assets.paths我已经按照这个答案在application.rb中添加了这些路径,那么您在
styles.css.erb
中遇到了问题。尝试像这样给它加前缀:
styles.css.scss.erb
以添加sass功能。我们可以看看你的
styles.css.erb
是什么样子吗?我现在已经用styles.css更改了。并在带有
/assets/museosans_500-webfont.ttf
的页面上添加了链接,之后我编译并立即运行。我已经在application.rb中添加了这些路径,根据这个答案,那么您在
style.css.erb
中遇到了问题。尝试像这样给它加前缀:
styles.css.scss.erb
以添加sass功能。我们可以看看你的
styles.css.erb
是什么样子吗?我现在已经用styles.css更改了。并在带有
/assets/museosans_500-webfont.ttf
的链接上添加了链接,之后我编译了它,现在可以使用了。