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
但是我收到406错误,因为我希望表单呈现onixxml.xml.builder。它只是想呈现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吗?