Getting an error after rails s, after adding code

2019-09-06 01:39发布

问题:

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?

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)

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

回答1:

There really is a syntax error.

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

%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` 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.

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.