2012-02-22 4 views
1

今は完全に狂っています。ActiveAdminとCarrierwave with:has_many

私は2つのモデルがあります:プロジェクトとスクリーンショットを:

create_table "projects", :force => true do |t| 
    t.string "name" 
    t.text  "description" 
    t.boolean "isactive" 
    t.datetime "created_at", :null => false 
    t.datetime "updated_at", :null => false 
    t.string "slug" 
    t.string "logo" 
    t.string "teaser" 
end 

add_index "projects", ["slug"], :name => "index_projects_on_slug" 

create_table "screenshots", :force => true do |t| 
    t.integer "project_id" 
    t.string "image" 
    t.datetime "created_at", :null => false 
    t.datetime "updated_at", :null => false 
end 

プロジェクトモデルは、アップローダは現在未編集である

class Project < ActiveRecord::Base 

    attr_accessible :name, :description, :isactive, :slug, :logo, :teaser, :screenshots_attributes 

    scope :isactive, :conditions => ["isactive = ?",true] 

    mount_uploader :logo, LogoUploader 

    extend FriendlyId 
    friendly_id :name, use: [:slugged, :history] 

    has_many :screenshots 
    accepts_nested_attributes_for :screenshots 

end 

とスクリーンショットモデル

class Screenshot < ActiveRecord::Base 

    belongs_to :project, :polymorphic => true 
    mount_uploader :screenshots, ScreenshotUploader 

end 

スクリーンショットのように見えます

# encoding: utf-8 

class ScreenshotUploader < CarrierWave::Uploader::Base 

    # Include RMagick or MiniMagick support: 
    # include CarrierWave::RMagick 
    # include CarrierWave::MiniMagick 

    # Choose what kind of storage to use for this uploader: 
    storage :file 
    # storage :fog 

    # Override the directory where uploaded files will be stored. 
    # This is a sensible default for uploaders that are meant to be mounted: 
    def store_dir 
    "uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}" 
    end 

    # Provide a default URL as a default if there hasn't been a file uploaded: 
    # def default_url 
    # "/images/fallback/" + [version_name, "default.png"].compact.join('_') 
    # end 

    # Process files as they are uploaded: 
    # process :scale => [200, 300] 
    # 
    # def scale(width, height) 
    # # do something 
    # end 

    # Create different versions of your uploaded files: 
    # version :thumb do 
    # process :resize_to_fit => [300, 150] 
    # end 

    # Add a white list of extensions which are allowed to be uploaded. 
    # For images you might use something like this: 
    # def extension_white_list 
    # %w(jpg jpeg gif png) 
    # end 

    # Override the filename of the uploaded files: 
    # Avoid using model.id or version_name here, see uploader/store.rb for details. 
    # def filename 
    # "something.jpg" if original_filename 
    # end 

end 

そして今、私はこのフォームに

form do |f| 
    f.inputs "Project Details" do 
    f.input :name 
    f.input :logo, :as => :file, :hint => f.template.image_tag(f.object.logo.url) 
    f.input :teaser 
    f.input :description 
    f.input :isactive 
    f.has_many :screenshots do |s| 
     s.input :image, :as => :file 
    end 
    end 
    f.buttons 
end 

を使用してactiveadminからのスクリーンショットを追加しようとしている。しかし、私が得るすべては次のとおりです。

NoMethodError (undefined method `screenshots_changed?' for #<Screenshot:0xc940cd0>): 

私は最後の時間が、何のためにこれで遊んI試してみました:(

何か提案がありますか?

+0

小さなもの: の代わりにt.timestampsを使用できます。t.datetime "created_at"、:null => false t.datetime "updated_at"、:null => false – obenda

答えて

0

私は同じ問題を抱えていました。私はform do |f|ニーズactive_adminデフォルトに置き換えられると信じて

4

:あなたは、マイグレーション(移行すくいデシベルを):走っていることを確認してください

form(:html => { :multipart => true }) do |f| 
+0

マルチパートが問題であれば、そうではありませんブロック内に書かれた部分? 's.input:image、:multipart => true'編集:私の間違いは、両方の方法で行うことができるように見えます。 – jordancooperman

3
あなたがCarrierWaveを含め、この行の#のコメントを解除する必要が

を:: RMagick