deklarieren Ich möchte Lehrbücher in Zielseite suchen, aber es funktioniert nicht. Ich musste gehen/Lehrbücher Seite und dann kann ich suchen. Ich möchte auch Volltextsuche. Ich verwende Sonnenflecken & solr. Die Volltextsuche funktioniert jedoch nicht. Wenn ich einen Lehrbuchtitel namens "Algorithmus" habe. Wenn ich "algo" suche, möchte ich durchsuchbar sein. Kannst du helfen?Wie kann ich Pfad für bootstrap navbar Suchformular mit Rails
Ich habe Codes unten.
Ansichten/Layouts:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>
<% if content_for? :title %>
<%= yield :title %>
<% else %>
Udeal
<% end %>
</title>
<%= stylesheet_link_tag 'application', media: 'all', 'data-turbolinks-track' => true %>
<%= javascript_include_tag 'application', 'data-turbolinks-track' => true %>
<%= csrf_meta_tags %>
</head>
<body>
<%= render 'partials/navbar' %>
<%= render 'partials/flash_notification' %>
<%= yield %>
</body>
</html>
config/routes.rb:
Rails.application.routes.draw do
root 'home#index'
get '/about', to: 'home#about'
resources :textbooks
get '/textbooks/search', to: 'textbooks#search'
devise_for :users
_navbar.html.erb:
<form class="navbar-form navbar-left" role="search">
<div class="form-group">
<%= form_tag(textbooks_path, :method => "get", id: "search-form", html: {class: 'form-group'}) do %>
<%= text_field_tag :search, params[:search], placeholder: "Search all deals", class: "form-control" %>
</div>
<%= submit_tag "Search", :class => 'btn btn-default',:title => nil%>
<% end %>
</form>
mein TextbooksController:
class TextbooksController < ApplicationController
before_action :set_textbook, only: [:show, :edit, :update, :destroy]
def search
@search = Textbook.search do
keywords(params[:q])
end
end
def index
@textbooks = Textbook.all
@search = Textbook.search do
fulltext params[:search]
#keywords params[:search]
end
@textbooks = @search.results
end
Modell 0
Lehrbuch:
class Textbook < ActiveRecord::Base
belongs_to :user
searchable do
text :title, :default_boost => 2
text :subject
end
unten ist mein index.html.erb für Lehrbuch Seite
<div>
<%= form_tag textbooks_path, :method => :get do %>
<p>
<a style="color:#000000" title="Suggest!" data-toggle="popover" data-trigger="hover" data-content="Title or Subject">
<%= text_field_tag :search, params[:search] %>
</a>
<%= submit_tag "Search", :title => nil, class: "btn btn-success btn-sm" %>
<% end %>
</div>
EDIT:
Ich tippte Rake Routen:
Prefix Verb URI Pattern Controller#Action
root GET / home#index
about GET /about(.:format) home#about
search_textbooks GET /textbooks/search(.:format) textbooks#search
textbooks GET /textbooks(.:format) textbooks#index
POST /textbooks(.:format) textbooks#create
new_textbook GET /textbooks/new(.:format) textbooks#new
edit_textbook GET /textbooks/:id/edit(.:format) textbooks#edit
textbook GET /textbooks/:id(.:format) textbooks#show
PATCH /textbooks/:id(.:format) textbooks#update
PUT /textbooks/:id(.:format) textbooks#update
DELETE /textbooks/:id(.:format) textbooks#destroy
new_user_session GET /users/sign_in(.:format) devise/sessions#new
user_session POST /users/sign_in(.:format) devise/sessions#create
destroy_user_session DELETE /users/sign_out(.:format) devise/sessions#destroy
user_password POST /users/password(.:format) devise/passwords#create
new_user_password GET /users/password/new(.:format) devise/passwords#new
edit_user_password GET /users/password/edit(.:format) devise/passwords#edit
PATCH /users/password(.:format) devise/passwords#update
PUT /users/password(.:format) devise/passwords#update
cancel_user_registration GET /users/cancel(.:format) devise/registrations#cancel
user_registration POST /users(.:format) devise/registrations#create
new_user_registration GET /users/sign_up(.:format) devise/registrations#new
edit_user_registration GET /users/edit(.:format) devise/registrations#edit
PATCH /users(.:format) devise/registrations#update
PUT /users(.:format) devise/registrations#update
DELETE /users(.:format) devise/registrations#destroy
was Ihre Routen aussehen? – uzaif
in Ihrer Konsole Typ 'Rake Routen | Suche nach Grep. Kopieren Sie dann den Pfad und fügen Sie ihn in Ihre Formular-URL ein. – Emu
@Emu Ich habe gerade bearbeitet! –