Modify routes.rb
Rails.application.routes.draw do
root 'entries#index'
resources :entries do
collection do
get :search
end
end
end
change the form pathin searchon the index page :
<%= form_tag(search_entries_path, :method => :get, class: "search-form") do %>
<%= text_field_tag :search, params[:search], placeholder: "Search for previous entries..", class: "form-control" %>
<% end %>
Change your controller method:
def search
if params[:search]
@entries = Entry.search(params[:search]).order("created_at DESC")
else
@entries = Entry.all.order("created_at DESC")
end
end
create one template for the search method in Here you can access the object view/entries/search.html.erb @entries
Points of change I made:
1. routes.rb:
Rails URL- . paths URLs, .
resource . HTTP verbs URLs . CRUD .
, collection individual members of the collection.
:
, - :
resources :entries do
member do
get 'preview'
end
end
:
resources :entries do
collection do
get 'search'
end
end
A ID, member. , collection objects.
?
2. GET POST?
, GET POST , SO. GET POST , -, . , , , GET. .;)
.
GET ( - ), POST ( / ), PUT ( PATCH, ), , DELETE, .
:
, . :)