Я пытаюсь использовать ajax для отображения результатов поиска в приложении Ruby на rails. Тем не менее, после того, как я отправляю форму поиска, она показывает ошибку ActionController :: UnknownFormat в строке, где написано response_to response_to do | format |. Это не позволяет мне сделать частичное, и я не уверен, почему. Использование Rails 6.0.2.2
доступность / _searchform. html .erb
<form>
<%= simple_form_for(:search, :url => search_rides_path, :remote => true, :method => :get) do |f| %>
<div class="form-row">
<div class="form-group col-md-2">
<%= f.input :start_city, label: 'Start City', class: "form-control", error: 'Start address is mandatory, please specify one' %>
</div>
<div class="form-group col-md-4">
<%= f.input :start_street_address, label: 'Start Street Address', class: "form-control" %>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-2">
<%= f.input :end_city, label: 'Destination City', class: "form-control" %>
</div>
<div class="form-group col-md-4">
<%= f.input :end_street_address, label: 'Destionation Street Address', class: "form-control" %>
</div>
</div>
<div class="form-row">
<div class="form-group col-md-2">
<%= f.input :trip_date, as: :date, html5: true, inline_label: 'Yes, remember me', class: "form-control" %>
</div>
<div class="form-group col-md-2">
<%= f.input :trip_time, as: :time, html5: true, inline_label: 'Yes, remember me', class: "form-control" %>
</div>
<div class="form-group col-md-2">
<%= f.input :lowest_acceptable_price, label: 'Expected Price', class: "form-control" %>
</div>
</div>
<%= f.submit "Search", class: "btn btn-primary" %>
<% end %>
</form>
часть avilabilities_controller.rb
class AvailabilitiesController < ApplicationController
before_action :set_availability, only: [:show, :edit, :update, :destroy]
# respond_to :html, :json, :js
# GET /availabilities
# GET /availabilities.json
def index
@availabilities = Availability.unmatched
end
def search
if params[:search]
@availabilities = Availability.unmatched.search(params[:search])
if @availabilities
respond_to do |format|
format.js { render partial: 'availabilities/result.html'}
end
else
respond_to do |format|
flash.now[:alert] = "Could not find an availability"
format.js { render partial: 'availabilities/result.html'}
end
end
else
@availabilities = Availability.unmatched
end
end
end
доступность / поиск. html .erb
<p id="notice"><%= notice %></p>
<%= render 'searchform' %>
<div id="results">
</div>
доступность / _result. html .erb
<% if @availabilities %>
<%@availabilities.each do |availability|%>
<div class="card" style="width: 18rem;">
<div class="card-body">
<h5 class="card-title">Ride</h5>
<strong>Start city: </strong> <%= availability.start_city %><br>
<strong>Start street address: </strong><%= availability.start_street_address %><br>
<strong>End city: </strong><%= availability.end_city %><br>
<strong>End street address: </strong><%= availability.end_street_address %><br>
<strong>Trip Time: </strong><%= availability.trip_time %><br>
<strong>Price Requested: </strong><%= availability.lowest_acceptable_price %><br>
<br>
<a href="#" class="btn btn-primary">View Details</a>
<a href="#" class="btn btn-primary">Request Ride</a>
</div>
</div>
<% end %>
</div>
<% else %>
<h1> No results have been found </h1>
<% end %>
доступность / _result. js .erb
alert("hello world!")