I am using ActiveAdmin and Single Table Inheritance. I have a model "Simple Portfolio Model" that a variety of models that have similar portfolio fields inherit from. Also, I have a model "Asset" that image and video model inherit from. A Simple Portfolio Model has_one asset and asset belongs_to SimplePortfolioModel. I was able to create a form that send both the portfolio details and the uploaded assets through parameters and then to an action that will create both STI models. However, after being saved, the file is uploaded, but there are no fields such as url and items such as @storage and others are missing.
Any clues will definitely be appreciated.
ImageUploader:
class ImageUploader < CarrierWave::Uploader::Base
include CarrierWave::RMagick
storage :file
def store_dir
if model.portfolio_name
"uploads/#{model.portfolio_name.underscore}/#{mounted_as}/#{model.id}"
else
"uploads/#{model.class.to_s.underscore}/#{mounted_as}/#{model.id}"
end
end
...more code
end
The ActiveAdmin Create Action which dynamically creates Image model which inherits from Asset and calls the ImageUploader functions
ActiveAdmin.register Example do
params.permit .....
member_action :create, method: :post do
@model = Image.new
@model.portfolio_name = "Example"
uploader = ImageUploader.new(@model, :attachment)
uploader.store!(image_file_params)
@model.save
@example = Example.new(example_params)
if (@example.save)
@model.simple_portfolio_model_id = @example.id
@model.save
redirect_to :action => :show, :id => @example.id
else
flash[:error] = "Example couldn't be saved"
render :new
end
end
end
class Image < Asset
mount_uploader :attachment
end
class Asset < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
belongs_to :simple_portfolio_model
end
It is saving the file, alright, but is missing essential parts such as the url. So when I access the image like this:
I am using ActiveAdmin and Single Table Inheritance. I have a model "Simple Portfolio Model" that a variety of models that have similar portfolio fields inherit from. Also, I have a model "Asset" that image and video model inherit from. A Simple Portfolio Model has_one asset and asset belongs_to SimplePortfolioModel. I was able to create a form that send both the portfolio details and the uploaded assets through parameters and then to an action that will create both STI models. However, after being saved, the file is uploaded, but there are no fields such as url and items such as @storage and others are missing.
Any clues will definitely be appreciated.
ImageUploader:
Form:
The ActiveAdmin Create Action which dynamically creates Image model which inherits from Asset and calls the ImageUploader functions
end
end
It is saving the file, alright, but is missing essential parts such as the url. So when I access the image like this:
I get:
but then, I try:
and get
This is how a carrierwave model should look when you access it (s.image.attachment, for instance)
What am I missing? Thank you.