-2

I'm trying to generate pages for a new rails project but I keep getting this error.

    $ rails generate controller pages home
    /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `load':/Users/reidwahlbrink/Desktop/Hanna's Blog/config/initializers/session_store.rb:3: syntax error, unexpected tIDENTIFIER, expecting end-of-input
 ...re, key: '_Hanna's_Blog_session'
...                               ^ (SyntaxError)
from /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `block in load'
from /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:232:in `load_dependency'
from /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/dependencies.rb:241:in `load'
from /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/engine.rb:648:in `block in load_config_initializer'
from /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/activesupport-4.1.4/lib/active_support/notifications.rb:161:in `instrument'
from /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/engine.rb:647:in `load_config_initializer'
from /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/engine.rb:612:in `block (2 levels) in <class:Engine>'
from /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/engine.rb:611:in `each'
from /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/engine.rb:611:in `block in <class:Engine>'
from /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `instance_exec'
from /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/initializable.rb:30:in `run'
from /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/initializable.rb:55:in `block in run_initializers'
from /Users/reidwahlbrink/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:226:in `block in tsort_each'
from /Users/reidwahlbrink/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:348:in `block (2 levels) in each_strongly_connected_component'
from /Users/reidwahlbrink/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:418:in `block (2 levels) in each_strongly_connected_component_from'
from /Users/reidwahlbrink/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:427:in `each_strongly_connected_component_from'
from /Users/reidwahlbrink/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:417:in `block in each_strongly_connected_component_from'
from /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/initializable.rb:44:in `each'
from /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/initializable.rb:44:in `tsort_each_child'
from /Users/reidwahlbrink/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:411:in `call'
from /Users/reidwahlbrink/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:411:in `each_strongly_connected_component_from'
from /Users/reidwahlbrink/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:347:in `block in each_strongly_connected_component'
from /Users/reidwahlbrink/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each'
from /Users/reidwahlbrink/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `call'
from /Users/reidwahlbrink/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:345:in `each_strongly_connected_component'
from /Users/reidwahlbrink/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:224:in `tsort_each'
from /Users/reidwahlbrink/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/tsort.rb:205:in `tsort_each'
from /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/initializable.rb:54:in `run_initializers'
from /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/railties-4.1.4/lib/rails/application.rb:300:in `initialize!'
from /Users/reidwahlbrink/Desktop/Hanna's Blog/config/environment.rb:5:in `<top (required)>'
from /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application.rb:92:in `require'
from /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application.rb:92:in `preload'
from /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application.rb:140:in `serve'
from /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application.rb:128:in `block in run'
from /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application.rb:122:in `loop'
from /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application.rb:122:in `run'
from /Users/reidwahlbrink/.rvm/gems/ruby-2.1.2/gems/spring-1.1.3/lib/spring/application/boot.rb:18:in `<top (required)>'
from /Users/reidwahlbrink/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from /Users/reidwahlbrink/.rvm/rubies/ruby-2.1.2/lib/ruby/2.1.0/rubygems/core_ext/kernel_require.rb:55:in `require'
from -e:1:in `<main>'

I've also tried to run rails server and it will load the server and then exit and return this same error. I'm working my way through One Month Rails and was trying to set up my own project with what I had learned so far after watching the creating more pages lesson. Please help!

rbrink63
  • 3
  • 1
  • 2
    Show `config/initializers/session_store.rb`. There's clearly a syntax error in this file. – Marek Lipka Jul 28 '14 at 14:43
  • That file is currently blank, I just created this new project. Is there something that needs to be in there? – rbrink63 Jul 28 '14 at 14:54
  • And you're still getting syntax error? – Marek Lipka Jul 28 '14 at 14:55
  • @rbrink63 Your error says the problem is at Line 3 of `config/initializers/session_store.rb`, are you absolutely sure it's blank? – Dylan Markow Jul 28 '14 at 14:56
  • This file is absolutely blank in this project. However I checked `config/initializers/session_store.rb` in two other projects and they had the following in line 3 `Rails.application.config.session_store :cookie_store, key: '_Hannas_Blog_session'` The code I just pasted in is from another project that I created from scratch without the apostrophe in the name...this project allowed me to run the `rails generate controller pages` command with no issues. – rbrink63 Jul 29 '14 at 13:35
  • nvm, I did something silly. I changed the directory name to Hanna\'s Blog and this meant that Sublime could no longer find the directory that I had originally opened up, that's why the file was showing up as blank. I changed the name of the directory back to Hanna's Blog and reopened it. Lo and behold, I changed line 3 to '_Hanna\'s_Blog_session' and everything works. – rbrink63 Jul 29 '14 at 13:59

2 Answers2

3

You need to escape your apostrophe '_Hanna\'s_Blog_session' Or you can just use double quotes "_Hanna's_Blog_session"

The reason for this is that in the single quotes case you need to identify that the apostrophe is part of the string literal rather than the end of the string.

thedevlpr
  • 1,101
  • 12
  • 28
  • Where do I escape it? I can't edit that part that you included above. I put the back slash in the name of the project folder and re-entered the directory and got the same error. – rbrink63 Jul 28 '14 at 14:55
  • what ruby version are you using? `ruby --version` – thedevlpr Jul 28 '14 at 14:58
  • And you can definitely edit the file it's found in /config/initializers/session_store.rb – thedevlpr Jul 28 '14 at 15:02
  • `ruby 2.1.2p95 (2014-05-08 revision 45877) [x86_64-darwin13.0]` and I tried to add this `Rails.application.config.session_store :cookie_store, key: "_Hanna's_Blog_session" ` to /config/initializers/session_store.rb but Sublime tells me I can't save it for some reason – rbrink63 Jul 29 '14 at 13:50
  • nvm, I did something silly. I changed the directory name to `Hanna\'s Blog` and this meant that Sublime could no longer find the directory that I had originally opened up. I changed the name of the directory back to `Hanna's Blog` and reopened it. Lo and behold, I changed line 3 to `'_Hanna\'s_Blog_session'` and everything works. Thanks for not only answering my question but also explaining the reason behind it! – rbrink63 Jul 29 '14 at 13:57
2

You have a space and a single quote in your application's path:

/Users/reidwahlbrink/Desktop/Hanna's Blog/
                                  ^ ^

Probably from running:

rails new "Hanna's Blog"

This is going to cause many problems. You should delete that directory and instead run:

rails new hannasblog
Stefan
  • 109,145
  • 14
  • 143
  • 218
  • I did originally run `rails new "Hanna's Blog"`, and after creating a new directory using `rails new "Hannas Blog"` I have been able to successfully run `rails generate controller pages`. Is there a way to correctly name a file with apostrophes and spaces? or is that just something you shouldn't do? – rbrink63 Jul 29 '14 at 13:43
  • I've always been taught that you follow good naming convention by not using spaces or apostrophes in these kinds of situations. You can still name your files with this type of punctuation all you have to do is make sure you escape them when you try to access those directories or files (i.e. `cd Hanna\'s\ Blog`) – thedevlpr Jul 29 '14 at 13:55
  • @rbrink63 it's not worth it :-) – Stefan Jul 29 '14 at 13:58