can i perform validations on an uploader mounted column
14 views
Skip to first unread message
fugee ohu
unread,
Jan 31, 2019, 3:50:44 PM1/31/19
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ruby on Rails: Talk
I had to remove a validation on the :name column because my PictureUploader which uses Carrierwave is mounted on that column
mount_uploader :name, PictureUploader
This causes validation
validates :name, presence: true
to cause rows in pictures to be invalid for blank :name even though the name, just a filename, is in the database for that column
Walter Lee Davis
unread,
Jan 31, 2019, 4:38:52 PM1/31/19
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to rubyonra...@googlegroups.com
CarrierWave overloads the accessor for the attachment column to respond with the entire uploader model object. This is normal for CarrierWave.
There are other attachment systems (I'm fond of Shrine) that use a different, less-surprising approach. In Shrine, you would have a column called picture_data and an attachment called picture. That way you can keep the difference between db column and virtual object separate.
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to Ruby on Rails: Talk
If the uploader's mounted on that column do I still have to validate it ?
Walter Lee Davis
unread,
Jan 31, 2019, 5:13:47 PM1/31/19
Reply to author
Sign in to reply to author
Forward
Sign in to forward
Delete
You do not have permission to delete messages in this group
Copy link
Report message
Sign in to report message
Show original message
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to rubyonra...@googlegroups.com
I haven't used Carrierwave in a number of years, but I think that it implements some validators of its own. You should investigate the documentation for CW.