我是编程新手,正在阅读 Hartl 的 Ruby on Rails 教程并停留在第 2.3.1 节。
我需要为 Micropost 资源创建一个新的脚手架,并将新的数据模型迁移到数据库中。
我已经使用以下方法成功创建了一个新的脚手架:
$ rails generate scaffold Micropost content:string user_id:integer
作为回报,我看到:
$ rails generate scaffold Micropost content:string user_id:integer
invoke active_record
create db/migrate/20130711181712_create_microposts.rb
create app/models/micropost.rb
invoke test_unit
create test/unit/micropost_test.rb
create test/fixtures/microposts.yml
invoke resource_route
route resources :microposts
invoke scaffold_controller
create app/controllers/microposts_controller.rb
invoke erb
create app/views/microposts
create app/views/microposts/index.html.erb
create app/views/microposts/edit.html.erb
create app/views/microposts/show.html.erb
create app/views/microposts/new.html.erb
create app/views/microposts/_form.html.erb
invoke test_unit
create test/functional/microposts_controller_test.rb
invoke helper
create app/helpers/microposts_helper.rb
invoke test_unit
create test/unit/helpers/microposts_helper_test.rb
invoke assets
invoke coffee
create app/assets/javascripts/microposts.js.coffee
invoke scss
create app/assets/stylesheets/microposts.css.scss
invoke scss
identical app/assets/stylesheets/scaffolds.css.scss
当我进入下一步迁移时,我输入:
$ bundle exec rake db:migrate
并看到迁移成功:
== CreateUsers: migrating ====================================================
-- create_table(:users)
-> 0.0020s
== CreateUsers: migrated (0.0020s) ===========================================
== CreateMicroposts: migrating ===============================================
-- create_table(:microposts)
-> 0.0030s
== CreateMicroposts: migrated (0.0030s) ======================================
我运行了一个本地主机,看到所有微博视图都显示正常,并且可以创建、更新和删除微博。
现在问题出在下一步,我需要更改文件夹“app/models/micropost.rb”以使用长度验证。但是,我没有看到模型文件夹中列出的“micropost.rb”文件。我只看到上一个练习中的“.gitkeep”和“user.rb”文件。
这让我相信迁移并不成功,尽管被告知并且我不知道该怎么做。请帮忙。