データベース内の多くのフィールドを検索するために Searchlogic を使用しています。それらのフィールドの 1 つは :has_may, :through => の関係であり、私はそれを機能させることができません。
モデルの関連部分は次のとおりです。
ソース.rb:
class Source < ActiveRecord::Base
has_many :authorships
has_many :authors, :through => :authorships
end
Authorship.rb:
class Authorship < ActiveRecord::Base
belongs_to :source
belongs_to :author
end
著者.rb:
class Author < ActiveRecord::Base
has_many :authorships
has_many :sources, :through => :authorships
end
次に、私の見解では、次のようになります。
<% form_for @search do |f| %>
<fieldset><legend>Search the Online Medieval Sources Bibliography</legend>
<% f.fields_for @search.conditions do |sources| %>
<%= sources.hidden_field :live_not_null %>
<p>
Text Name:
<%= sources.text_field :text_name_like, :size => 95 %> <br />
<% sources.fields_for :author do |authors| %>
Medieval Author:
<%= authors.text_field :name_like, :size => 90 %>
<% end %> <br />
Modern Editor/Translator:
<%= sources.text_field :editor_like, :size => 80 %> <br />
</p>
<% end %>
</fieldset>
<p>
<%= f.submit "Search" %>
</p>
<% end %>
検索ページは正常にロードされますが、「送信」ボタンを押すと次のエラーが表示されます。
Searchlogic::Search::UnknownConditionError in SourcesController#index
The author is not a valid condition. You may only use conditions that map to a named scope
SourcesController のコードは次のとおりです。
クラス SourcesController < ApplicationController
def index
query = if params[:search] then
params[:search][:hash]
end
@search = Source.search(query)
@sources = @search.all
end
パラメータは次のとおりです。
パラメータ: {"commit"=>"Search", "search"=>{"hash"=>{"text_name_like"=>"canterbury", "date_begin_greater_than_or_equal"=>"", "author"=>{"name_like" =>""}, "editor_like"=>"", "link_not_blank"=>"0", "trans_none_not_null"=>"0", "trans_other_not_null"=>"0", "trans_english_not_null"=>"0", "trans_french_not_null"=>"0", "region_like"=>"", "live_not_null"=>"", "app_facsimile_not_null"=>"0", "date_end_less_than_or_equal"=>""}, "order"=>"" }}
ここで何が起こっているかについて何か考えがある人はいますか? エラー メッセージをさらに表示する必要がありますか?
どうもありがとう!