我是铁杆的新手,我们将不胜感激。
我实现了宝石搜索,每当我点击我的应用程序的搜索按钮时,我都会得到图像下方的错误
我的终端目前有以下错误:
Started GET "/adverts?utf8=%E2%9C%93&q%5Btitle_cont%5D=accountant&commit=search" for 127.0.0.1 at 2015-06-13 20:17:47 +0100
Processing by AdvertsController#index as HTML
Parameters: {"utf8"=>"✓", "q"=>{"title_cont"=>"accountant"}, "commit"=>"search"}
Completed 404 Not Found in 4ms (ActiveRecord: 0.7ms)
ActiveRecord::RecordNotFound (Couldn't find Userr without an ID):
app/controllers/adverts_controller.rb:16:in `index'
我不确定为什么我会得到上述错误以及为什么它指向我 我的advert_controller.rb的索引操作,而不是指向 我的static_pages_controller.rb的搜索动作
任何帮助或建议,以扩大我对此错误的理解 将不胜感激。我有我所有的编码
adverts_controller.rb
class AdvertsController < ApplicationController
respond_to :html, :xml, :json
before_action :set_advert, only: [:show, :edit, :update, :destroy]
def index
@userr = Userr.find(params[:userr_id])
@adverts = @userr.adverts.order("created_at DESC")
respond_with(@adverts)
end
def show
...
end
def new
...
end
def edit
...
end
def create
...
end
def update
...
end
def destroy
...
end
end
static_pages_controller.rb
class StaticPagesController < ApplicationController
respond_to :html, :xml, :json
def searchpg
@search = Advert.search(params[:q])
@adverts = @search.result
end
end
的routes.rb
Rails.application.routes.draw do
resources :contacts, only: [:new, :create]
get 'contact', to: 'contacts#new'
resources :forms
devise_for :userrs
resources :userrs do
resources :adverts
member do
get 'applicants'
end
end
root 'static_pages#homepg'
get 'search', to: 'static_pages#searchpg'
end
视图/ static_pages / searchpg.html.erb
<h1>search jobs</h1>
<p>Find me in app/views/static_pages/approachpg.html.erb</p>
<div>
<%= search_form_for(@search) do |f| %>
<%= f.label :title_cont %>
<%= f.text_field :title_cont %>
<%= f.submit 'search' %>
<% end %>
</div></br>
<div>
<table>
<thead>
<tr>
<th>Published</th>
<th>Title</th>
<th>Content</th>
<th>City</th>
<th>Town</th>
<th>Postcode</th>
<th></th>
</tr>
</thead>
<tbody>
<% @adverts.each do |advert| %>
<tr>
<td><%= advert.created_at.strftime("%B %d, %Y") %></td>
<td><%= link_to advert.title, userr_advert_path(advert.userr, advert) %></td>
<td><%= advert.content %></td>
<td><%= advert.city %></td>
<td><%= advert.town %></td>
<td><%= advert.postcode %></td>
<td><%= link_to 'Apply now', userr_advert_path(advert.userr, advert) %></td>
</tr>
<% end %>
</tbody>
</table>
</div>
广告属性:
2.1.2 :001 > Advert.new
=> #<Advert id: nil, title: nil, content: nil, category_jobtype_id: nil, category_positiontype_id: nil, salarystart: nil, salaryend: nil, category_country_id: nil, city: nil, town: nil, postcode: nil, category_editorialapproval_id: nil, category_applicationrequest_id: nil, created_at: nil, updated_at: nil, userr_id: nil, category_advert_id: nil>
2.1.2 :002 >
advert.rb [model]
class Advert < ActiveRecord::Base
belongs_to :category_jobtype
belongs_to :category_positiontype
belongs_to :category_country
belongs_to :category_editorialapproval
belongs_to :category_applicationrequest
belongs_to :category_advert
belongs_to :userr
has_many :forms
has_many :userjs, through: :forms
end