0

Consulted by the ruby guides for the rails routing syntax http://guides.rubyonrails.org/routing.html I am writing the rule.

get 'guess/(index)', :to "guess#index"

This syntax is giving me an error and only after the => sign is working correctly.

get 'guess/(index)', :to => "guess#index"

What is the right syntax ?

4

1 回答 1

2

to:,不是:to

这不是 Rails 语法问题,而是 Ruby 语法问题。您缺少=>:key => value哈希语法的“哈希火箭”(),或者您需要移动冒号并使用to:key: value语法:

# Prior to Ruby 1.9:

get 'guess/(index)', :to => "guess#index"

#  or, in modern Ruby:

get 'guess/(index)', to: "guess#index"
于 2013-09-11T18:40:48.293 回答