When I search from the search form, I get an error similar to the picture below.
ActionController:: UnknownFormat (SearchsController #index is missing a template for this request format and variant.
request.formats: ["text/html"]
request.variant: [ ]
NOTE! For XHR/Ajax or API requests, this action would normally respond with 204 No Content: an empty white screen. Since you're loading it in a web browser, we assume that you expected to actually render a template, not nothing, so we're showing an error to be extra-clear. If you expect 204 No Content, carry on. That's what you'll get from an XHR or API request. Give it a shot.):
If you look at the terminal, it says that there is no app/views/blog/index.html.erb, but I think both route and view are set.Is there anything else missing?
I would appreciate it if you could teach me.
Thank you for your cooperation.
Below is the code and file of the image post (same content)
railsg model search name:string
rakedb:migrate
search.rb
class Search <ApplicationRecord
as class method in def self.search(search)#self.
If search# Controller passed parameter != nil, search title column for partial match
Search.where (['name LIKE?', %#{search}%'])
else
Search.all# Show all.
end
end
end
index.html.erb
<%=form_tag searches_path, :method=>'get'do%>
<p>
<%=text_field_tag:search,params[:search]%>
<%=submit_tag "Search", :name=>nil%>
</p>
<%end%>
<%=yield%>
routes.rb
#get'searchs/index'
# get "blog/index" = > "searchs #index"
resources:searchs
searchcontroller.rb
class SearchesController<ApplicationController
def index
# Pass the parameters obtained in the View Form to the model
@projects=Search.search(params[:search])
end
end
Create model file for
Install search form in
SearchesController#index is missing a template for this request format and variant.
The error is
app/views/blog/index.html.erb missing
Do you need app/views/searches/index.html.erb instead?Or specify that the render method uses the BlogController#index template.
© 2024 OneMinuteCode. All rights reserved.