添加代码以预编译图像资产后,在 rails s 之后出现错误? [英] Getting an error after rails s, after adding code to precompile image asset?

查看:61
本文介绍了添加代码以预编译图像资产后,在 rails s 之后出现错误?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚解决了这个问题的图像资产编译问题-->为什么此代码在我的所有页面上呈现背景图像,而不仅仅是我的索引操作?

I just fixed an image asset compiling problem at this question-->Why is this code rendering a background image on all of my pages, instead of just my index action?

现在我在启动 Rails 服务器时收到以下错误消息??

Now I am getting the below error message when starting up my rails server??

config/initializers/assets.rb:9: syntax error, unexpected tXSTRING_BEG, expecting end-of-input (SyntaxError)

我无法在 Internet 上的任何地方找到修复程序.谢谢.初始化程序/资产.rb :

I can't find a fix anywhere on the internet. Thanks. initializers/assets.rb :

Rails.application.config.assets.version = '1.0'

Rails.application.config.assets.precompile += %w( background.css )` to ` config/initializers/assets.rb

推荐答案

确实存在语法错误.

Rails.application.config.assets.precompile += %w( background.css )` to ` config/initializers/assets.rb

%w() 是一种将字符串数组指定为单词的方法.任何由 ()s 和空格分隔的元素都被认为是一个单独的数组元素.

%w() is a way to specify an array of strings as words. Any element, delimited by ()s and spaces is considered a separate array element.

`to` 是 Ruby 在您的错误消息中所说的 XSTRING,它是一个可执行字符串:它作为命令运行to 在您的操作系统中,其输出作为字符串返回.但在这种情况下不是.Ruby 不希望它在数组之后立即写入,并且不清楚如何处理它.这正是错误消息所说的.由于代码不清楚,Ruby 停止了.

`to` is what Ruby calls a XSTRING in your error message, it's an executable string: it is run as a command to in your operating system and its output is returned back as a string. Not in this case though. Ruby doesn't expect it being written right after an array and it's unclear what to do with it. And it's exactly what the error message says. With the code unclear, Ruby halts.

最后一件事:在大多数情况下,字符串应该被包裹在 "' 中.然而,它们是不同的.双引号允许字符串插值(诸如 "thi#{5.0.to_i}" 之类的结构),而单引号则不然.

And the last thing: strings in most cases should be wrapped in " or '. These are different, however. Double quotes allow for string interpolation (constructs such as "thi#{5.0.to_i}") while single quotes don't.

这篇关于添加代码以预编译图像资产后,在 rails s 之后出现错误?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆