1

I am trying to use Carrierwave with multiple image uploads. After following the carrierwave guide on github I do:

rails g migration add_images_to_areas images:json
rake db:migrate

But seeing on my schema, my areas table does not show up, instead I get:

# Could not dump table "areas" because of following StandardError
#   Unknown type 'json' for column 'images'

What should I do now? Should I use another type instead of json, but what?

Sorry if this is an amateur question.

2 Answers 2

2

Databases by default don't support arrays, hashes and so on.

In order to do it, you can serialize it adding this code to your model:

class Name_class < ActiveRecord::Base
  serialize :column_name, JSON
end

And change the migration field :

add_column :user_preferences, :text

This will insert the info as Text into the database and, when you retrieve it , it will be JSON.

More info about serialization here RailsGuides#Serialize

Sign up to request clarification or add additional context in comments.

11 Comments

Databases support arrays or json, with some extensions.
I didn't know that . I always use serialize when i need a json or array field in the database. Thank you for the info though,
@RubenBarbosa thank for the tip, I will try it and get right back at you.
Hollywar detected, choise by yourself. dev.mysql.com/doc/refman/5.7/en/json.html
Can you put the code of your controller?, the action when you save it in the database. I think the problem is there.
|
1

I am not sure as to what was going wrong here, The github tutorial of Carrierwave was suggesting :json, but you don't have to do so.

Everything went fine after I just followed the guide for multiple image upload with Carrierwave here: Rails 4 multiple image or file upload using carrierwave

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.