Rails 回形针图像未显示在 cloud9 服务器上

Rails Paperclip images not showing up in on cloud9 server

我正在使用回形针将图像上传到 cloud9 虚拟环境 (ubuntu) 上的 rails 应用程序。有一个电影模型,每个电影对象都有一个与之关联的图像。

class Movie < ActiveRecord::Base
    belongs_to :user
    belongs_to :category
    has_attached_file :movie_img, styles: { medium: "250x350>", thumb: "325x475>" }, default_url: "/images/style/missing.png"
    validates_attachment_content_type :movie_img, content_type: '/\Aimage\/.*\Z/'
end

视图看起来像这样

    <% @movies.each do |movie| %>
            <%= image_tag movie.movie_img.url(:movie_index), class: "movie" %>
    <% end %>

但是网站上没有显示图像。

生成的 html 中图像的路径如下所示

system/movies/movie_imgs/000/000/010/movie_index/fileName.jpg?1465401579 The images are present in the actual directory as I can see from the file explorer of Cloud9.

当我打开这个图片地址时,它显示以下错误。

No route matches [GET] "/system/movies/movie_imgs/000/000/011/movie_index/fileName.png"

同样在config/environments/development.rb中我写了下面这行代码

  Paperclip.options[:command_path] = "/usr/bin/"

因为当我在终端输入 which convert 时,会出现以下内容。

/usr/bin/convert

我哪里错了?如何让图片出现在服务器中?

编辑 我还生成了必要的迁移,我的电影 table 看起来像这样。

create_table "movies", force: :cascade do |t|
    t.string   "title"
    t.text     "description"
    t.string   "director"
    t.date     "release_date"
    t.datetime "created_at",             null: false
    t.datetime "updated_at",             null: false
    t.integer  "user_id"
    t.integer  "category_id"
    t.string   "movie_img_file_name"
    t.string   "movie_img_content_type"
    t.integer  "movie_img_file_size"
    t.datetime "movie_img_updated_at"

结束

静止图像未显示。

您似乎正在声明一个视图助手来调整图像 (:movie_index) 的大小,但电影模型中没有定义。

您需要在模型中为 :movie_index 声明助手和大小:

class Movie < ActiveRecord::Base
    belongs_to :user
    belongs_to :category
    has_attached_file :movie_img, styles: { movie_index: "300x300>" medium: "250x350>", thumb: "325x475>" }, default_url: "/images/style/missing.png"
    validates_attachment_content_type :movie_img, content_type: '/\Aimage\/.*\Z/'
end

编辑:

确保您已经生成了必要的迁移:

rails g paperclip Movie movie_img

一定要阅读Paperclip documentation