0
votes

I'm following a video tutorial to set the Paperclip gem up on my rails project.

So the steps I've taken so far..

  • Installed ImageMagick on Terminal - brew install imagemagick
  • Installed the Paperclip gem - gem "paperclip", "~> 4.2"
  • Added the following to my house.rb model file:

    has_attached_file :image, styles: { large: "600x600", medium: "300x300", thumb: "150x150#" } validates_attachment_content_type :image, content_type: /\Aimage/.*\Z/

So all in all my house.rb model file now looks like this:

class House < ActiveRecord::Base
validates :title, presence: true
validates :price, presence: true
validates :description, presence: true
validates :image, presence: true

has_attached_file :image, styles: { large: "600x600", medium: "300x300", thumb: "150x150#" }
validates_attachment_content_type :image, content_type: /\Aimage\/.*\Z/
end

At which point I need to add a migration using the migration generator, so I type in rails g migration house image and it isn't creating a timestamped database migration file in the folder and the terminal is returning:

Usage:
rails new APP_PATH [options]

and a whole bunch of options. In the tutorial it should return something like:

create db/migrate/20150205123408_add_attachment_image_to_posts.rb

I'm not sure where I'm going wrong here and I'm new to ruby-on-rails so any help would be really appreciated!

1
When you run the generator, you have previously run bundle install and are inside your rails project directory? The Usage: rails new APP_PATH help only appears when not in a Rails root directory.Douglas F Shearer
Rookie error, I'd done bundle install yes but I wasn't in the right directory. I apologise. Thanks for your help!user2498890

1 Answers

0
votes

If problem persist, create the migration manually.

 create_table "media", force: :cascade do |t|
    t.string   "image_video_file_name"
    t.string   "image_video_content_type"
    t.integer  "image_video_file_size"
    t.datetime "image_video_updated_at"
    t.string   "text", default: ""
    t.datetime "created_at"
    t.datetime "updated_at"
    t.integer  "user_id", null: false
  end

  add_index "media", ["user_id"], name: "index_media_on_user_id", using: :btree