简体   繁体   English

ROR:语法错误,意外的tSTRING_BEG,期待keyword_do或'{'或'('(SyntaxError)

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

I was trying my first rails application. 我正在尝试我的第一个rails应用程序。

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'

You have to define the route inside a do .. end block like this: 您必须在do .. end块中定义路由,如下所示:

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

I highly recommend you to read the Official Ruby on Rails Documentation for Routing 我强烈建议您阅读官方Ruby on Rails文档以获取路由

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: routes.rb文件就是一个很好的例子:

# 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... 等等...

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 RoR:语法错误,意外的tSTRING_BEG,期望')' - RoR: syntax error, unexpected tSTRING_BEG, expecting ')' 语法错误意外tSTRING_BEG - Syntax error unexpected tSTRING_BEG 语法错误,意外的keyword_class,期待keyword_do或'{'或'('' - Syntax error, unexpected keyword_class, expecting keyword_do or '{' or '(' 语法错误,非预期的tSYMBEG,期望keyword_do或 - syntax error, unexpected tSYMBEG, expecting keyword_do or 语法错误,非预期的tSYMBEG,期望keyword_do或'{'或'(' - syntax error, unexpected tSYMBEG, expecting keyword_do or '{' or '(' 获取Rails错误“语法错误,意外的tSYMBEG,期待keyword_do或'{'或'('” - Getting Rails error “syntax error, unexpected tSYMBEG, expecting keyword_do or '{' or '('” Ruby On Rails 5 错误,期望关键字_do 或 '{' 或 '(' - Ruby On Rails 5 Error expecting keyword_do or '{' or '(' 出现Rails错误“语法错误,意外的tSYMBEG,期望使用keyword_do或'{'或'('before_save:create_unique_profile_id - Getting Rails error "syntax error, unexpected tSYMBEG, expecting keyword_do or '{' or '(' before_save :create_unique_profile_id RoR指南第6章不断获取语法错误,出现意外的tIDENTIFIER,期望出现keyword_end(SyntaxError - RoR Tutorial Chapter 6 keep getting syntax error, unexpected tIDENTIFIER, expecting keyword_end (SyntaxError 语法错误,意外',',期待')'RoR - syntax error, unexpected ',', expecting ')' RoR
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM