Beginner of programming. I think there is something wrong with how to ask questions, but thank you.
In order to learn Rails, I have created an article posting app by myself.
I would like to ask about the number of images displayed on the article list page because I could not implement it as intended.
- You can post articles
- You can post images (multiple photos)
- Edit/delete articles (not implemented)
- User registration (not implemented)
- ruby '2.5.1'
- rails '5.2.3'
When displaying posted articles on the list page, posted images and titles are displayed.
There is no problem when you post a single image, but when you post multiple images, the displayed images and titles will be displayed.
I would like to implement this display so that only one sheet can be displayed, but it does not work well.
.right-content.w-50.overflow-auto.vh-100 [email protected] articles.each do | article | = link_to article_path (article), class: "text-dark text-decoration-none" do .article-list.card.m-4.shadow-sm .row .article-list-img.col-4 -article.images.each do | image | = image_tag image.variant (resize: "150x150"). processed, class: "article-list-img" .article-list-description.card-body h5.card-title = article.title
Because ActiveStorage is used, the submitted images are stored in the array, so we proceeded with the implementation of an image that can be extracted from the array as shown below, but it cannot be extracted successfully.
# Example ① = image_tag image  .variant (resize: "150x150"). processed, class: "article-list-img" # Example ② = image_tag image.first.variant (resize: "150x150"). processed, class: "article-list-img"
I tried as much as possible by myself and tried and errored, but I can not solve it, so I would like advice on corrections and reference articles. Thank you in advance.
Answer # 1
-article.images.each do | image | = image_tag image.variant (resize: "150x150"). processed, class: "article-list-img"
Showing all images in a loop
-if article.images.count>0 = image_tag article.images.first.variant (resize: "150x150"). processed, class: "article-list-img"
I don't know which one to display, so I'd like to display only the first one.
- ruby on rails - i want to display the posted image in the background using image_tag or url_for
- ruby on rails - the image cannot be saved in s3 and cannot be displayed in the view aws :: sigv4 :: errors :: missingcredentials
- ruby - i installed carrierwave with rails, but i can't see the image
- ruby on rails - i want to display all the images in the [rails] directory in the browser!
- ruby on rails - i want to display search results
- ruby on rails - [rails beginner] i want to display the posted content on my page
- ruby on rails - image cannot be saved (activestorage installed) null in image of table
- ruby on rails 6 - [rails] i want to update the display of chat room participants etc in real time
- ruby - [rails] i want to create an image link using the url of the image output using active storage
- ruby on rails - creating an image posting application where the data entered in the form is not saved
- ruby - rails comment function display
- ruby on rails - about image posting page argumenterror
- ruby on rails - i want to display the numbers entered in the line graph of chart kick
- ruby on rails - i want to display the posted images in a random order (get information from the record)
- ruby on rails 6 - i want to change the display of the product detail page according to the user's conditions
- ruby on rails - [rails] how to round (omission and display) the character string of link_to
- ruby on rails - i want to display the latest posting date and time by creating a simple bulletin board
- ruby on rails - about image distribution on heroku and s3
- ruby on rails - display all tweets of the user you are following on the top page
- ruby - i want to display specific columns in rails in descending order of numbers