我仍在學習Ruby,並且仍然從我的手冊中複製粘貼。但是我遇到了一個問題,我不知道如何解釋以及我做錯了什麼。所以在這裏,它是: 我要創建這個新的對象:Ruby on Rails 3,創建新對象時出現語法錯誤
second_page = Page.new (:name=>"Second page", :position=>1, :permalink => "second")
,我得到了一個錯誤:
Loading development environment (Rails 3.0.10)
ruby-1.9.2-p290 :001 > second_page = Page.new (:name=>"Second page", :position=>1, :permalink => "second")
SyntaxError: (irb):1: syntax error, unexpected tASSOC, expecting ')'
...econd_page = Page.new (:name=>"Second page", :position=>1, ...
... ^
(irb):1: syntax error, unexpected ',', expecting $end
...age.new (:name=>"Second page", :position=>1, :permalink => ...
... ^
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/commands/console.rb:44:in `start'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/commands/console.rb:8:in `start'
from /usr/local/rvm/gems/ruby-1.9.2-p290/gems/railties-3.0.10/lib/rails/commands.rb:23:in `<top (required)>'
from script/rails:6:in `require'
from script/rails:6:in `<main>'
,但是,如果我這樣做:
ruby-1.9.2-p290 :002 > second_page = Page.new :name=>"Second page", :position=>1, :permalink => "second"
=> #<Page id: nil, subject_id: nil, name: "Second page", permalink: "second", position: 1, visible: false, created_at: nil, updated_at: nil>
這似乎工作。 我從手冊中得到了一個例子,我想知道發生了什麼? 而沒有()我不知道我該怎麼做的東西與該對象? 謝謝
你有沒有嘗試刪除new'和'('之間的空間' – rubish