Search code examples
ruby-on-railsrake

Rails migration failed with an error syntax


I am very new to rails an d I have this in my model

PreGit::Application.routes.draw do

  resources :microposts
  resources :users

  match '/help',    to:'static_pages#help'
  match '/about',   to:'static_pages#about'
  match '/contact', to:'static_pages#contact'

  root_path => '/'
  root_url => 'http://localhost:3000/'

end

But when running bundle exec rake db:migrate I get that :

syntax error, unexpected tSYMBEG, expecting kDO or '{' or '('
  match '/help',    to:'static_pages#help'
                    ^

Someone could help


Solution

  • It seems like this is not a Rails issue but a Ruby version issue.

    In Ruby 1.8.x the hash syntax was

    :to => static_pages#help'
    

    but Ruby 1.9.x supports

    to:'static_pages#help'
    

    so probably you are trying to run an app developed under Ruby 1.9.x under your Ruby 1.8.x

    Try running the same app under Ruby 1.9.x

    If you are using rvm then try this

    rvm list #will list all your ruby versions

    If you have ruby 1.9.x installed

    rvm use ruby-1.9.x