I want to get column values from the table

Asked 2 months ago, Updated 2 months ago, 1 views

I'm making a movie introduction site now.
I got movie information from a certain site, including title, movie image, director, release date, and so on.MySQL already has data in the title column, image column, director column, and so on.

I want to match the title to the movie image.
There is an image of the movie in the products table, and the image is now displayed on the website.
And I want to match the title, but I can't do it well.
NoMethodError in ProductsController#index
The error undefined method `order' for appears.

to products_controller.rb
class ProductsController<RankingController
  def index
    @products=Product.new(@title).order('id DESC').limit(20)←This is what matters
    @title=Product.select ("title")

  def show

I think the new(@title) when defining the @products variable is wrong, but I don't know how to describe this part.


2022-09-30 14:08

1 Answers

Product.new(@title) did not understand what they wanted to do.
I think I can use the following code to get 20 items and rearrange them.

@products=Product.limit(20).order('id DESC')

Read and combine the references around here.

2022-09-30 14:08

If you have any answers or tips

© 2022 OneMinuteCode. All rights reserved.