Home>
Overview of the application i am trying to create

It is a simple WEB application that uses Rails to vote for the movies on the list after the user logs in, and the order of the movies on the list page changes according to the voting result.

For the table, prepare a "Movie table" that stores individual movie information, a "User table" that stores individual user information, and a "Vote table" (intermediate table) that says which user voted for which movie. did.

ActiveRecord :: Schema.define (version: 2020_10_14_063658) do
  create_table "movies", force:: cascade do | t |
    t.string "title"
    t.text "story"
    t.string "image"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.integer "points"
  end
  create_table "users", force:: cascade do | t |
    t.string "name"
    t.string "email"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
    t.string "password_digest"
    t.index ["email"],

 name: "index_users_on_email", unique: true
  end
  create_table "votes", force:: cascade do | t |
    t.integer "user_id"
    t.integer "movie_id"
    t.text "comment"
    t.datetime "created_at", precision: 6, null: false
    t.datetime "updated_at", precision: 6, null: false
  end
end
The problem that is occurring this time

I was able to access the user detail page without any problems in the local environment, but when I try to access the user detail page in the production environment, "The page you were looking for doesn't exist" is displayed.

Looking at it using the developer tools, this is my guess, but the computer misunderstood that there is a file named "1" for 1 in "/ users/1" (1 is the user's id). I think there is.

What I actually tried

-Rewritten config.assets.compile = false to config.assets.compile = true.
-Completely disable turbolinks (comment out the gem and comment out the part that is being read)
-Definition of root path

The part that seems to have a problem
User detail page code<% = provide (: title, @ user.name)%> <i></i>Profile                        <i></i>name           <% = @ user.name%>                         <i></i>email           <% = @ user.email%>        <br /><% if current_user&&current_user == @user%><% = link_to'edit', edit_user_url (current_user), class:'btn btn-primary'%><% = link_to'Delete', user_url (@user), method:: delete, data: {confirm: "Are you sure I want to delete?"}, Class:'btn btn-danger'%><% end%><hr /><% ='List of works voted by users'%><br><% if @movies! = []%>                <% # Prevent duplication when voting for the same movie multiple times%>        <% @ movies.uniq.each do | movie |%>                                <% if movie.image?%><% = image_tag movie.image.url, style:'height: 400px;'%>                <% end%>                                         <% = movie.title%>                     <p><% = text_num_over (movie.story)%></p>                                    <% = link_to'See details', movie_url (movie), class: "m-3 btn btn-primary"%>                        <% end%>        <% else%>    <% ='No work voted by user'%><% end%>
def index
    @users = User.all
  end
  def show
    @user = User.find (params [: id])
    @votes = Vote.where (user_id: @ user.id)
    # An array that stores movie information that users have voted for or commented on
    @movies = movies (@votes)
  end
  def movies (vote_arr)
        # An array that stores movie information that users have voted for or commented on
        movies = []
        vote_arr.each do | vote |
            movies<<Movie.find (vote.movie_id)
        end
        return movies
    end

We will post the missing resources as needed. We will wait for the answer.

  • Answer # 1

    Looking at the log
    Couldn't find Movie with id = 1It looks like
    Maybe hereMovie.find (vote.movie_id)is not it. In other words, when vote.movie_id is 1, I wonder if there is no movie number 1 data. So I feel that it will be solved if I prepare the data.

    Also

          movies = []
            vote_arr.each do | vote |
                movies<<Movie.find (vote.movie_id)
            end
            return movies


    Is

    Movie.where (id: vote_arr.pluck (: movie_id))


    I think I can write it as well.