提交表单搜索时没有路由匹配

时间:2015-04-15 17:51:03

标签: ruby-on-rails mongoid

我在Rails中遇到路由问题。我正在尝试构建一个搜索表单。我在root_path(static_pages#index)视图中有一个html表单。我想在提交此表单时使用关键字,其中包含这些标记的点的结果显示在由controllersController控制的另一个视图中(搜索#index)。当我提交控制台告诉我'没有路线匹配得到'/搜索''我不知道为什么

这是我路线的代码

配置/ routes.rb中

Rails.application.routes.draw do
 get 'maps/:name' => 'maps#spot', :as => :spot_map


 devise_for :users, :controllers => { :omniauth_callbacks => "users/omniauth_callbacks" }

 devise_scope :user do
   get 'sign_out', :to => 'devise/sessions#destroy', :as => :destroy_session
 end

 resources :users do
  resources :spots do
    resources :offers
  end
 end

 root 'static_pages#index'
 get 'search/:query' => 'searches#index', :as => "query"
 get 'search/spot/:id' => 'searches#show', :as => :search_result
 get 'tags/:tag' => 'static_pages#index', :as => "tag"
 get 'register' => 'static_pages#register', :as => :register
 get 'users/:id/profile' => 'profiles#show', :as => :user_profile

 get 'maps/homepage' => 'maps#homepage', :as => :homepage_map


 mount Attachinary::Engine => "/attachinary"
end

这是视图的代码(static_pages #index),其中我有html表单。 /static_pages/views/index.html.erb我尝试过使用action =“/ search”

<form action="query" method='get'>
    <div class="row collapse postfix-round">
      <div class="small-10 columns">
          <input id="home-placeholder" class="" type="search" name="query" placeholder="">      
      </div>
      <div class="small-2 columns">
        <input type="submit" class="button postfix" value="Buscar"/>
      </div>
    </div>
  </form>

这是我控制器的代码

控制器/ searches_controller.rb

class SearchesController

 def index
   @user = current_user if current_user
   @spots = Spot.full_text_search(params[:query])
 end 

end

1 个答案:

答案 0 :(得分:0)

将操作设置为<%= search_path %>