Home>
I want to return the URL of the image (has_many_attached) saved in ActiveStorage with json.
It does n’t work.
The reason is that url_for cannot be stored in the array.
The JSON I want to return is below.
Thank you in advance.
{
"id": 10,
"uuid": null,
"title": null,
"detail": null,
}
class Image
class ImagesController
-
Answer # 1
Related articles
- ruby on rails - no data when using v-if
- ruby - i want to solve the n + 1 problem when using rails where method in loop processing
- ruby on rails - about deploying apps using s3 function
- ruby on rails - time out when connecting with deployment using ec2, rds
- ruby - [rails] i want to create an image link using the url of the image output using active storage
- ruby on rails - [rails 6] i'm using bootstrap 4, but the layout collapses only after logging out
- ruby on rails - [rails] i want to define routing using the resources method
- [ruby on rails 6] i implemented the tag function using acts-as-taggable-on, but i can't jump to the linked article from the list
- ruby - i want to collect the same records using rails group and get the value
- i want to keep data consistent using [ruby on rails] transaction and payjp
- ruby on rails 5 - star evaluation using raty stars become very large
- ruby - i want to get it at intervals by searching using rails active record
- ruby on rails - i'm using payjpjs v2 i want to register the card name
- ruby on rails - the graph is not displayed well in the app using rails a 0 will be entered in the date when no data is entered,
- ruby on rails - i can't comment out using htmlerb begin
- ruby - [rails] i want to deploy a rails application using elastic beanstalk
- ruby - [rails 5] i want to send an email to a specific user using action mailer
- ruby - i want to output the array in the yml file to the view with rails
- ruby - about routing using rails collection
- ruby - [rails] i want to find the date difference using the model created_at
Related questions
- ruby - passing variables using render partial
- ruby - #i want to see a list of posts for that user on the user details page
- ruby - implementation of friendly forwarding
- ruby - i installed carrierwave with rails, but i can't see the image
- ruby - about rails controller new action
- ruby - rails page does not open
- [ruby] i'm having trouble with nomethoderror
- ruby - [search function] acquisition of products associated with users
- ruby - even if each statement is used, the contents of the db cannot be displayed in order and an error occurs
- ruby - if i include the'omniauth-facebook'gem, do i need to install the'omniauth' gem as well?
has_many_attached: myImage There is more than one myImage?
If you set it as has_many_attached: myImages, the later mistakes will be reduced.
I think it won't work because url_for (myImage) is passed an array (something like).
I've never used url_for (myImage) like that, so I can go with it.
myImages.map {| myImage | url_for (myImage)}
If myImage exists but may not have myImage.attached?
myImages.map {| myImage | url_for (myImage) if myImage.attached?} .compadt