[英]ruby on rails syntax error with match
When creating my application using ROR, I continually receive a syntax error when I use: 使用ROR创建应用程序时,使用以下代码时,我会不断收到语法错误:
FitsbyApp::Application.routes.draw do
match '/help', to: 'static_pages#help'
match '/about', to: 'static_pages#about'
match '/contact', to: 'static_pages#contact'
end
I am using Rails 3.2.8. 我正在使用Rails 3.2.8。 Could it be that I don't have the right version of Rails or Ruby?
可能是我没有正确版本的Rails或Ruby吗?
This is the error I get when I run the match: 这是我进行比赛时遇到的错误:
rb:245:in `load': /Users/dannygaeta/rails_projects/fitsby_app/config/routes.rb:2: syntax error, unexpected ':', expecting kEND (SyntaxError)
rb:245:在`load'中:/Users/dannygaeta/rails_projects/fitsby_app/config/routes.rb:2:语法错误,意外的':',期望kEND(SyntaxError)
I get this for each match. 每次比赛我都会得到这个。 Any ideas what I am doing wrong?
有什么想法我做错了吗?
The error you're getting is (probably) from the trailing colon in to:
. 您收到的错误(可能是)从结尾的冒号
to:
。 That said, I'm no rails expert but shouldn't the route in question look like this? 就是说,我不是Rails专家,但是所讨论的路线不应该是这样吗?
match '/help' => 'static_pages#help'
see http://guides.rubyonrails.org/routing.html 看到http://guides.rubyonrails.org/routing.html
This sounds like you're using ruby 1.8.x. 听起来您正在使用ruby1.8.x。 Ruby 1.9 introduced a new syntax for hashes,
Ruby 1.9引入了一种新的哈希语法,
match 'foo', to: 'bar'
Is the same as 是相同的
match 'foo', :to => 'bar'
Your routes file appears to be using the newer syntax. 您的路由文件似乎正在使用较新的语法。
In Rails 3: 在Rails 3中:
match 'logout' => 'user_sessions#destroy', :as => :logout
OR 要么
match '/help' => 'static_pages#help'
In Rails 4: 在Rails 4中:
match 'logout' => 'user_sessions#destroy', :as => :logout, via: [:get, :post] 匹配'logout'=>'user_sessions#destroy',:as =>:logout,通过:[:get,:post]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.