Why aren't params being passed?
Why aren't :q params passing to the controller?!
Here's the controller code:
def advanced_search
@search = Isbn.where(:client_id => current_user.client_id).search(params[:q])
@search.build_grouping unless @search.groupings.any?
@isbns = params[:distinct].to_i.zero? ? @search.result : @search.result(distinct: true)
respond_with @isbns
end
Here's application_helper with the build_grouping bit it:
def setup_search_form(builder)
fields = builder.grouping_fields builder.object.new_grouping, object_name: 'new_object_name', child_index: "new_grouping" do |f|
render('grouping_fields', f: f)
end
Here's the form:
<%= search_form_for @search, url: advanced_search_isbns_path, html: {method: :post} do |f| %>
<% setup_search_form f %>
#...
<%= render 'results' %>
Here's the trace:
Processing by IsbnsController#advanced_search as HTML
Parameters: {"utf8"=>"✓", "authenticity_token"=>"P074clk3UDe3cNNEG6IZ6TXm2q+fr8dMJfJwSBSx/1c=", "q"=>{"g"=>{"0"=>{"m"=>"or"}}}, "commit"=>"Search"}
Here's the source of search_form_for:
# File 'lib/ransack/helpers/form_helper.rb', line 4
def search_form_for(record, options = {}, &proc)
if record.is_a?(Ransack::Search)
search = record
options[:ur开发者_如何学Pythonl] ||= polymorphic_path(search.klass)
elsif record.is_a?(Array) && (search = record.detect {|o| o.is_a?(Ransack::Search)})
options[:url] ||= polymorphic_path(record.map {|o| o.is_a?(Ransack::Search) ? o.klass : o})
else
raise ArgumentError, "No Ransack::Search object was provided to search_form_for!"
end
options[:html] ||= {}
html_options = {
:class => options[:as] ? "#{options[:as]}_search" : "#{search.klass.to_s.underscore}_search",
:id => options[:as] ? "#{options[:as]}_search" : "#{search.klass.to_s.underscore}_search",
:method => :get
}
options[:as] ||= 'q'
options[:html].reverse_merge!(html_options)
options[:builder] ||= FormBuilder
form_for(record, options, &proc)
end
Here's the source of search:
# File 'lib/ransack/search.rb', line 16
def initialize(object, params = {}, options = {})
params ||= {}
@context = Context.for(object)
@context.auth_object = options[:auth_object]
@base = Nodes::Grouping.new(@context, 'and')
build(params.with_indifferent_access)
end
In fact, here's the whole chuffing lot.
Plus: all the routes for the model, included for completeness:
resources :isbns, only: :index do
match 'advanced_search' => 'isbns#advanced_search',
on: :collection, via: [:get, :post], as: :advanced_search
end
resources :isbns do
get :profit, :on => :member
get :workings, :on => :member
put :copyisbn, :on => :member
get :onixxml, :on => :member
collection do
post 'edit_multiple'
put 'update_multiple'
get 'onix'
get 'add_subschemes'
get 'xmp'
get 'profitindex'
delete 'destroy_multiple'
end
end
The models file is very busy, so do ask for more, but here are some of the associations: Isbn.rb: attr_accessible :marketingtexts_attributes, :prices_attributes #etc has_many :marketingtexts, :dependent => :destroy has_many :supplies, :dependent => :destroy
Marketingtext.rb
attr_accessible :user_id, :created_at, :legacycode, :updated_at, :client_id, :isbn_id, #etc
belongs_to :isbn
before_save :map_legacy_codes
validates :client_id, :presence => true
Supply.rb
attr_accessible :user_id, :client_id, :isbn_id, :prices_attributes, #etc
belongs_to :isbn
has_many :supplydetails, :dependent => :destroy
has_many :prices, :through => :supplydetails
accepts_nested_attributes_for :supplydetails
I can run the cloned ransack demo code on my machine. In my own app, I've excluded all the javascript except jquery and the search script. I'm increasingly thinking it's a conflict with another gem or some bit of code.
精彩评论