【问题标题】:Rails paperclip gem image display errorRails 回形针 gem 图像显示错误
【发布时间】:2013-10-13 09:24:01
【问题描述】:

大家好,我正在使用来自 https://github.com/thoughtbot/paperclip 的回形针宝石和来自 http://railscasts.com/episodes/134-paperclip 的导轨。

我在使用后无法显示我的图像:

<%= image_tag @post.photo.url %>

在我的帖子显示页面“show.html.erb”上。显示断开的链接图像而不是图像本身。

它在图像的 HTML 中有以下内容:

有没有人有任何提示来解决这个问题。提前致谢。

///////////////// 型号

class Post < ActiveRecord::Base
  has_many :comments, as: :commentable, dependent: :destroy
  validates :name, presence: true,
  length: { minimum: 5}
  has_attached_file :photo
end

/////////// 架构

create_table "posts", force: true do |t|
    t.string   "name"
    t.date     "date"
    t.time     "time"
    t.text     "description"
    t.text     "dresscode"
    t.decimal  "price"
    t.datetime "created_at"
    t.datetime "updated_at"
    t.string   "image"
    t.string   "photo_file_name"
    t.string   "photo_content_type"
    t.integer  "photo_file_size"
    t.datetime "photo_updated_at"
  end

【问题讨论】:

  • 您可以在模型中指定图片路径和url。在 github 自述文件中查看。
  • 很难在没有实际操作的情况下调试它。你有机会向我们展示比一行更多的代码吗?喜欢该表的模型和数据库架构吗?
  • 对不起,我已经更新了这个问题。
  • 您确定,您在表格中有图片网址,请检查photo_file_name 中的Database
  • 是的,我的架构文件中有 photo_file_name 字段

标签: ruby-on-rails ruby-on-rails-3 ruby-on-rails-3.2 rubygems


【解决方案1】:

既然您使用的是 Rails 3.2,为什么不尝试将其添加到您的 Post 模型中:

attr_accessible :photo

【讨论】:

  • 在测试时运气不佳,就像它不保存图像一样
【解决方案2】:

我认为您在上传照片后已在照片属性 i 模型中添加了选项,请尝试重新上传照片一次!

【讨论】:

  • 请你重新解释一下这个 RSB 谢谢,我试过了,但它没有用,它在图像的 HTML 中有以下内容:
  • 你试过上传不同扩展名的图片吗?! (jpg, gif, ..)
猜你喜欢
  • 2014-11-14
  • 1970-01-01
  • 2019-07-15
  • 1970-01-01
  • 2017-05-04
  • 1970-01-01
  • 1970-01-01
  • 2013-04-15
  • 1970-01-01
相关资源
最近更新 更多