Reputation: 3612
I'm trying to add tags to the Image model in RefineryCMS (trying on 1.0.8 and 2.0.4), have added attr_accessible :tag_list, required acts-as-taggable and setup the views, but the problem is that the tags only save when editing/updating a previously uploaded image - not when uploading for first time, even though it uses the same form...
Any ideas?
It happens on every version of rails and Refinery I have tried...
The tags are going through in the post when looking at logs, just not saving...
Upvotes: 1
Views: 408
Reputation: 1949
I had a similar issue and eventually find the cause of the extra-attributes (in your case the :tag_list) not being saved on new image upload.
If you look at ::Refinery::ImageController
you'll see that the create action actyally create the image with :
unless params[:image].present? and params[:image][:image].is_a?(Array)
@images << (@image = ::Refinery::Image.create(params[:image]))
else
params[:image][:image].each do |image|
@images << (@image = ::Refinery::Image.create(:image => image))
end
end
params[:image][:image]
is an Array when multiple multiple file uploed is enabled (by default it is). But then the action only use take the array values when creating the images, ignoring the other params.
I quickly write the below work-around that allow to save the other params on multiple image upload :
unless params[:image].present? and params[:image][:image].is_a?(Array)
@images << (@image = ::Refinery::Image.create(params[:image]))
else
images_params = params[:image].dup
images_params.delete(:image)
params[:image][:image].each do |image|
@images << (@image = ::Refinery::Image.create({:image => image}.merge(images_params)))
end
end
It's probably not the most elegant solution bu it does the trick.
To use it in your app, you'll have to create a decorator for the ::Refinery::ImageController
to copy and edit the create action in it. (see 'Extending a Controller' in Refinery's Guides)
Upvotes: 1