Metasearch gem は次のようなものを生成します。
Started GET "/isbns/onixxml?utf8=%E2%9C%93&search%5Btitle_contains%5D=flickers&5D=&commit=Search" for 127.0.0.1 at 2011-08-14 09:40:39 +0100
Processing by IsbnsController#onixxml as HTML
Parameters: {"utf8"=>"✓", "search"=>{"title_contains"=>"flickers", "commit"=>"Search"}
Isbn Load (8.1ms) SELECT "isbns".* FROM "isbns" WHERE "isbns"."client_id" = 4 AND ("isbns"."title" LIKE '%flickers%')
Completed 406 Not Acceptable in 54ms
しかし、フォームで onixxml.xml.builder をレンダリングしたいので、406 エラーが発生します。そして、htmlをレンダリングしたいだけです。コードを表示:
= semantic_form_for @search, :url => onixxml_isbns_path, :action => :onixxml, :html => {:method => :get} do |f|
%ol.search#slickbox
= f.input :title_contains, :label => "Title"
= f.buttons do
= f.submit 'Search'
コントローラ:
def onix
@title = "ISBNs"
@search = Isbn.where(:client_id => current_user.client_id).search(params[:search])
@filename = 'report.csv'
@isbns = @search.order(sort_column + " " + sort_direction)
if @search.nil?
@isbns = Isbn.where(:client_id => current_user.client_id)
end
session[:query] = @isbns.map(&:id)
respond_to do |format|
format.html
end
end
def onixxml
@title = "ISBNs"
@search = Isbn.where(:client_id => current_user.client_id).search(params[:search])
@isbns = @search.order(sort_column + " " + sort_direction)
if @search.nil?
@isbns = Isbn.where(:client_id => current_user.client_id)
end
session[:query] = @isbns.map(&:id)
respond_to do |format|
format.xml
end
end
Metasearch を使用してその XML をレンダリングできますか?