Как прикрепить изображение к объекту с ActiveStorage в грабли? - PullRequest
0 голосов
/ 28 сентября 2018

Я использую ActiveAdmin и ActiveStorage для управления объектами Card в моем приложении.При работе с интерфейсом ActiveAdmin для создания новой карты со всеми ее свойствами, включая изображение, все работает нормально.Но когда я пытаюсь использовать задачу rake для заполнения базы данных сотнями карт, она терпит неудачу, и я получаю ActiveSupport::MessageVerifier::InvalidSignature: ActiveSupport::MessageVerifier::InvalidSignature

popdb.rake:

desc 'Populate db'
task :popdb => [:environment] do 
    puts 'Generating categories...'

    5.times do
        category = Category.create(title: Faker::Color.color_name)
        puts "Created category \"" + category.title + "\""
        50.times do
            card = Card.create!(
                retailer: Faker::Company.name,
                category: category,
                offer_type: Faker::Company.buzzword,
                first_purchase: Faker::Company.industry,
                credit_limit: Faker::Number.between(10, 50) * 100,
                image: Faker::Placeholdit.image("100x50", 'jpg', :random))
            puts "Created card \"" + card.retailer + "\""
        end
    end
end

cards_controller.rb:

class CardsController < ApplicationController
    def index
        @cards = Card.all
        @cards = @cards.where(category_id: params[:category_id]) if params[:category_id]
    end

    def create
        card = Card.create!(card_params)
    end

    private
    def card_params
        params.require(:card).permit(:image, :retailer, :category, :offer_type, 
                                                                 :first_purchase, :credit_limit)
    end
end

cards.rb:

ActiveAdmin.register Card do
    permit_params :image, :retailer, :offer_type, :first_purchase, :credit_limit, :category_id

    form title: 'New Card' do |f|
      inputs 'Details' do
        input :retailer
        li "Created at #{f.object.created_at}" unless f.object.new_record?
        input :category
        input :offer_type
        input :first_purchase
        input :credit_limit
        input :image, as: :file
      end
      para "Press cancel to return to the list without saving."
      actions
    end

    show do
        attributes_table do
            row :retailer
            row "Image" do |card|
                image_tag url_for(card.image)           
            end
        end
    end

    index do
        column "Image" do |card|
            image_tag url_for(card.image), class: 'admin-image'         
        end
        column :retailer
        column :category
        column :offer_type
        column :first_purchase
        column :credit_limit
        actions
    end
end
...