【发布时间】:2015-04-05 05:27:02
【问题描述】:
我正在关注video tutorial,以便在我的 rails 项目中设置 Paperclip gem。
所以到目前为止我采取的步骤..
- 在终端上安装 ImageMagick - brew install imagemagick
- 安装了 Paperclip gem - gem "paperclip", "~> 4.2"
-
在我的 house.rb 模型文件中添加了以下内容:
has_attached_file:图像,样式:{ 大:“600x600”,中:“300x300”,拇指:“150x150#”} validates_attachment_content_type :image, content_type: /\Aimage/.*\Z/
所以我的 house.rb 模型文件现在看起来像这样:
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
此时我需要使用迁移生成器添加迁移,所以我输入 rails g migration house image 并且它没有在文件夹中创建带时间戳的数据库迁移文件并且终端正在返回:
Usage:
rails new APP_PATH [options]
还有一大堆选项。在本教程中,它应该返回如下内容:
create db/migrate/20150205123408_add_attachment_image_to_posts.rb
我不确定我在哪里出错了,而且我是 ruby-on-rails 的新手,所以非常感谢任何帮助!
【问题讨论】:
-
当你运行生成器时,你之前运行过
bundle install并且在你的rails 项目目录中?Usage: rails new APP_PATH帮助仅在不在 Rails 根目录中时出现。 -
Rookie 错误,我已经完成了捆绑安装,是的,但我不在正确的目录中。我道歉。感谢您的帮助!
标签: ruby-on-rails gem paperclip