我正在尝试构建待办任务应用程序。我创建了应用程序rails new
,在gemfile中指定了依赖项,运行了bundle install
,使用rails generate model Task title:string note:text completed:date
生成了模型,使用了rake db:migrate
进行了更改。
下一个命令是使用Task.create
创建任务。但是,出现以下错误:
Task.create(title: 'First task', note: 'This task was created inside the rails console')
-bash: syntax error near unexpected token `title:'
我也尝试过在“第一个任务”之后不使用逗号,并在逗号之前使用空格。
此语法错误不应该发生。有什么想法可能是问题吗?
最佳答案
您需要先在Rails控制台中创建此类任务。
通过在bash提示符中执行以下命令(在Rails应用程序目录中)输入rails console
:
$ rails console
然后,您可以从控制台创建任务:
> Task.create(title: 'First task' note: 'This task was created inside the rails console')
关于ruby-on-rails - -bash : syntax error near unexpected token,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21522000/