user2492364
user2492364

Reputation: 6693

ROR: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '(' (SyntaxError)

I was trying my first rails application.

But got the following error:

/Users/WWW/.rvm/gems/ruby-2.1.5/gems/activesupport-4.2.0/lib/active_support/dependencies.rb:268:in `load': /Users/WWW/railsbridge/first-app/config/routes.rb:3: syntax error, unexpected tSTRING_BEG, expecting keyword_do or '{' or '(' (SyntaxError)
+ get 'welcome',to: 'topics#welcome'
       ^
/Users/WWW/railsbridge/first-app/config/routes.rb:3: syntax error, unexpected ',', expecting keyword_end
+ get 'welcome',to: 'topics#welcome'

Here is the code:

resources :topics
+ get 'welcome',to: 'topics#welcome'

Upvotes: 3

Views: 3789

Answers (2)

Andy Lampert
Andy Lampert

Reputation: 67

As well as reading the guides to help get you started as mentioned above, also read the comments provided in the code to help you get started. The routes.rb file is a great example:

# The priority is based upon order of creation: first created -> highest priority.
  # See how all your routes lay out with "rake routes".

  # You can have the root of your site routed with "root"
  # root 'welcome#index'

  # Example of regular route:
  #   get 'products/:id' => 'catalog#view'

  # Example of named route that can be invoked with purchase_url(id: product.id)
  #   get 'products/:id/purchase' => 'catalog#purchase', as: :purchase

etc...

Upvotes: 0

K M Rakibul Islam
K M Rakibul Islam

Reputation: 34318

You have to define the route inside a do .. end block like this:

  resources :topics do
    get 'welcome', to: 'topics#welcome'
  end

I highly recommend you to read the Official Ruby on Rails Documentation for Routing

Upvotes: 2

Related Questions