Question

C:\Users\MEGHA>rails new sagar_blog
      create
      create  README.rdoc
      create  Rakefile
      ... <snip> ...
Using turbolinks (2.2.1)
Using uglifier (2.5.0)
Your bundle is complete!
Use `bundle show [gemname]` to see where a bundled gem is installed.

C:\Users\MEGHA>cd sagar_blog

C:\Users\MEGHA\sagar_blog>rails generate scaffold post title:string \ body:text
      invoke  active_record
      ... <snip> ...
      create      app/assets/stylesheets/posts.css.scss
      invoke  scss
      create    app/assets/stylesheets/scaffolds.css.scss

C:\Users\MEGHA\sagar_blog>rails generate scaffold comment post_id:integer  body:
text
      invoke  active_record
      create    db/migrate/20140402091132_create_comments.rb
      ... <snip> ...
      invoke  scss
   identical    app/assets/stylesheets/scaffolds.css.scss

C:\Users\MEGHA\sagar_blog>rake db:migrate
== 20140402091036 CreatePosts: migrating ======================================
-- create_table(:posts)
rake aborted!
StandardError: An error has occurred, this and all later migrations canceled:

undefined method `text' for :t:SymbolC:/Users/MEGHA/sagar_blog/db/migrate/201404
02091036_create_posts.rb:6:in `block in change'
C:/Users/MEGHA/sagar_blog/db/migrate/20140402091036_create_posts.rb:3:in `change
'
C:in `migrate'
Tasks: TOP => db:migrate
(See full trace by running task with --trace)
Was it helpful?

Solution

You called:

\Users\MEGHA\sagar_blog>rails generate scaffold post title:string \ body:text

remove the excess \:

\Users\MEGHA\sagar_blog>rails generate scaffold post title:string body:text

\ is actually a hard blank, which causes the body field to be called body (with a blank before the name), this causes the migration file to generate a line t.text : body instead of t.text :body, which fails the migration (and probably later will fail other stuff as well).

OTHER TIPS

You probably used text instead of :text in your migration.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top