I'm working in a Rails Spree app, I was making my own form and methods to add products, everything was working fine until I had to add an image to my product.
In spree there is a assets table with a "viewable_id" field that contains the id of the product, but I have no idea of how, manually, add a new asset to this table from my ProductsController.
In my form I use a field file_field.
And this is the method in my ProductsController, it works fine but I can't realize how to add a new asset whit the id of my current product.
def newproduct
@product = Product.new();
#render '/spree/home/newproduct'
end
def createproduct
@name = params[:product][:name];
@description = params[:product][:description];
@price = params[:product][:price];
@image = params[:product][:image];
@available_on = params[:product][:available_on];
@meta_description = params[:product][:meta_description];
@meta_keywords = params[:product][:meta_keywords];
abort a
@product = Product.new({
:name => @name,
:description => @description,
:available_on => @available_on,
:user_id => spree_current_user.id,
:meta_description => @meta_description,
:meta_keywords => @meta_keywords,
:price => @price,
:image => @image});
if @product.save!()
redirect_to "/tutienda", :notice => "The product has been added";
else
render '/spree/products/newproduct'
end
end
Aucun commentaire:
Enregistrer un commentaire