0

我已经安装了回形针和 imagemagick,并将代码实现到我的模型和视图文件中。我有一个名为“图片”的数据库列,无论我是否上传图片,它都是空的。图片实际上存在于/public/system/decks/pictures/000/000/019/medium文件夹中。我可以在那里看到所有上传的图片,但我无法显示它们,因为数据库是空的。

我的模型:

class Deck < ActiveRecord::Base
  attr_accessible :picture

  has_attached_file :picture, :styles => { :medium => "300x300>", :thumb => "100x100>" }
  attr_accessor :picture_file_name
  attr_accessor :picture_content_type
  attr_accessor :picture_file_size
  attr_accessor :picture_updated_at

我的观点:

<%= form_for @deck,:url => decks_path, :html => { :multipart => true } do |f| %>
  <%= f.file_field :slika %>

我的迁移:

class AddAttachmentPictureToDecks < ActiveRecord::Migration
  def change
    add_column :decks, :picture, :attachment
  end
end

所以我在我之前提到的那个文件夹中得到了图片,但是picture我的甲板表中的列是空的。我无法用 获得图片<%= image_tag @deck.picture.url(:medium) %>,因为我@deck.picture.url持有 a /pictures/original/missing.png,我的@deck.picture.path和我的@deck.picture.picture_file_name也没有显示任何内容。

谢谢你。

4

1 回答 1

0

最后,看起来我混合了旧语法和新语法,我无法在数据库中正确获取字段。看起来 attr_accessors 是不必要的

于 2012-08-04T10:50:29.407 回答