良い一日。私の問題は、準備が整ったプロジェクトでランサックを使用しようとしていることです。diff 言語と will_paginage を使用します。現在、私は得る
No Ransack::Search object was provided to search_form_for!
コントローラーのインデックスアクションにアクセスしようとすると。検索を機能させるにはどうすればよいですか?
コントローラ:
def index
if params[:set_locale]
redirect_to articles_path(locale: params[:set_locale])
else
if params[:q]
@search = Article.search(params[:q])
logger.debug '! IF 1'
@articles = @search.result(:distinct => true).
paginate page: params[:page], order: 'created_at desc',
per_page: 5 # load all matching records
else
logger.debug('! ELSE 2')
@articles = Article.paginate page: params[:page], order: 'created_at desc',
per_page: 5
end
respond_to do |format|
format.html # index.html.erb
format.json { render json: @articles }
end
end
end
更新 1 はい、私に反対票を投じる場合は、わかりましたが、何のために説明してもらえますか?
更新 2 とビュー
<%= search_form_for @q do |f| %>
<%= f.label :articles_title_start %>
<%= f.text_field :articles_title_start %><br />
<!-- etc... -->
<%= f.submit :value=>'Search' %>
<% end %>
更新 3 モデル
class Article < ActiveRecord::Base
attr_accessible :text, :title
validates :title, :presence=>true,:uniqueness=>true
validates :text, :presence=>true
end