Reputation: 142
I have been using paperclip to upload and fetch image(s) url. My question is how do I select the logo column?
for eg: User table structure
id
,name
, logo_file_name
, logo_content_type
+ more columns
when I do u = User.find(1).logo
getting the result which is great. Now when I'm doing u = User.select('name', 'logo').where('something')
receiving error saying there is no such column as u.logo which is clear to me, since there is no column that's why it's giving me error, but how do fetch image url in later condition.
Upvotes: 2
Views: 675
Reputation: 142
I have solved this question by myself here is a quick answer to it, need to select all 4 columns which are generated by paperclip for example i.e. users.logo_file_name, users.logo_content_type, users.logo_file_size, users.logo_updated_at
So when we do
u = User.select('logo_file_name, logo_content_type, logo_file_size, logo_updated_at').where(id: 29)
and then doing
u.first.logo
Getting the image URL.
Thanks!
Upvotes: 1
Reputation:
If you don't include logo columns ActiveRecord won't be able to serialise that.
So if you want instances of User to respond to logo then just include that in your select statement.
Upvotes: 0