The page that should have been rendered does not appear.

Asked 2 years ago, Updated 2 years ago, 63 views

Ruby on Rails 6
Amazon Linux 2
Amazon EC2

Search on the video site → There was a problem while displaying the search results screen.
1. Search using the search form in the common layout
2. Search by search function:
Where
Video table with filename (:key) or category name (:category) 3. Render
search results screen with search function 4. Search results screen (search_result): List search results

The search results screen (search_result) that should have been rendered does not appear.

Rendered s3 files/search_result.html.erb with in layouts/application (Duration: 3.8ms | Allocations: 628)

Instead, the home screen that you set to rootURL appears.
It was not transitioned to root because I was not logged in.
I'm having trouble with this kind of problem for the first time.

Rails.application.routes.drawdo
  root's3 files#home'
  resources —users do
    resources —channels
  end
  get's3files/home', to:'s3files#home'
  get's3files/music', to:'s3files#music'
  get's3files/movie', to:'s3files#movie'
  get's3files/program', to:'s3files#program'
  get's3files/game', to:'s3files#game'
  get's3files/news', to:'s3files#news'
  get's3files/sports', to:'s3files#sports'
  get's3files/learning', to:'s3files#learning'
  post's3files/search', to:'s3files#search'
  get's3files/search_result', to:'s3files#search_result'
  resources —s3 files
  resources:comments
  resources:sessions, only: %i [create]
end

##s3files_controller.rb

class S3 filesController<ApplicationController
  
  skip_before_action —Check_logged_in
  
  -----------------------------------------------------------

  def home
    @s3files=S3files.all
    @trend=S3file.joins(:one_day_view).order(count::desc).limit(10)
  end

  -----------------------------------------------------------
  
  def search
    if params [:key]
      @s3files=S3file.where (key:params[:key])
    else params [:category]
      @s3files=S3file.where (key:params[:key])
    end
    render 'search_result'
  end
    
  
  default search_result
  end
  
  private
  -----------------------------------------------------------

    defs3file_params
      param.require(:s3file).permit(:key,:image,:category,:channel_id)
    end

  -----------------------------------------------------------
end

<!DOCTYPE html>
<html>
  <head>
    <title> Stream</title>
    <%=csrf_meta_tags%>
    <%=csp_meta_tag%>

    <%=stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track': 'reload'%>
    <%=javascript_pack_tag 'application', 'data-turbolinks-track': 'reload'%>
  </head>
  <body>
   <header>
      <%if current_user%>
        <%=link_to(current_user.name,current_user)%>
      <%else%>
        <%=link_to "Guest Login (for viewing), sessions_path, method::post%>
      <%end%>
      <%=render's3 files/search_form'%>
    </header>
    <%=yield%>
  </body>
</html>

##_search_form.erb

<h2>Search Form</h2>
<%=form_with(model:S3file.new, url:'/s3files/search')do|form|%>
  <%=form.label:key%> 
  <%=form.text_field:key%>
  <%=form.label:category%> 
  <%=form.text_field:category%>
  <%=form.submit "Search" %>
<%end%>
<h1>Search Results</h1>
<%@s3files.each do | s3files | %>
  <p>Channel name: <%=s3file.channel.name%>/p>
  <p>Video Title:<%=s3file.key%>/p>
  <%=link_to(image_tag("https://bucket-for-stream.s3.ap-northeast-1.amazonaws.com/assets#{s3file.id.to_s}/#{s3file.image}"),s3file)%>
<%end%>

ruby-on-rails amazon-ec2

2022-09-30 17:43

1 Answers

I solved myself.
Rendered if the form_with argument is local:true.
The form_with in Rails 6.0 appears to display the page using asynchronous communication called ajax by default.
In short, the reason for the error was that I unintentionally used a new type of drawing process called ajax.


2022-09-30 17:43

If you have any answers or tips


© 2024 OneMinuteCode. All rights reserved.