-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Multiple models #42
base: master
Are you sure you want to change the base?
Multiple models #42
Conversation
…ptional parameters. Allows for the querying of multiple models.
|
||
object_method_hash.each do |object, method| | ||
#allow specifying fully qualified class name for model object | ||
#both object and method can be specified by object or id |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after #.
items = get_autocomplete_items(object, :model => get_object(object), \ | ||
:options => options, :term => term, :method => method) | ||
json += json_for_autocomplete(items, \ | ||
options[:display_value] ||= method, options[:extra_data], &block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [81/80]
Align the parameters of a method call if they span more than one line.
:model => get_object(object), | ||
:options => options, | ||
:term => term, | ||
:method => method |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the new Ruby 1.9 hash syntax.
:method => method | ||
) | ||
json += json_for_autocomplete(items, \ | ||
options[:display_value] ||= method, options[:extra_data], &block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [81/80]
Align the parameters of a method call if they span more than one line.
}) { @items } | ||
mock(@controller).get_autocomplete_items( | ||
Movie, | ||
{ :method => :name, :options => @options, :term => "query" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Redundant curly braces around a hash parameter.
Use the new Ruby 1.9 hash syntax.
|
||
mock(@controller).json_for_autocomplete(@items, :name, nil) | ||
get :autocomplete_movie_name, :term => 'query' | ||
get :autocomplete_name, :term => 'query' |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Use the new Ruby 1.9 hash syntax.
Prefer double-quoted strings unless you need single quotes to avoid extra backslashes for escaping.
:model => Movie, :method => :name, :options => @options, :term => "query" | ||
}) { @items } | ||
mock(@controller).get_autocomplete_items( | ||
{ :model => Movie, :method => :name, :options => @options, :term => "query" } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [89/80]
Redundant curly braces around a hash parameter.
Indent the first parameter one step more than the start of the previous line.
Use the new Ruby 1.9 hash syntax.
end | ||
|
||
context 'no term is specified' do | ||
should "render an empty hash" do | ||
mock(@controller).json_for_autocomplete({}, :name, nil) | ||
get :autocomplete_movie_name | ||
#mock(@controller).json_for_autocomplete(nil, {}, :name, nil) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing space after #.
:method => method | ||
) | ||
new_json = json_for_autocomplete(items, \ | ||
options[:display_value] ||= method, options[:extra_data], &block) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Line is too long. [81/80]
Align the parameters of a method call if they span more than one line.
@bluefalcon26 Looks like you put some time into this one. Can you provide some additional details on the use case here? Thanks. |
@bigtunacan We have one "search" box at the top of our site that we want to autocomplete matching on two models, employers and schools. Somewhat like Facebook has the search box that searches people, photos, pages, etc. Except this isn't a true search, it's just meant to allow autocomplete and navigation to those models' pages. Does that make sense? |
@bigtunacan We now have this in our search controller:
You could also do
|
@bluefalcon26 each individuals result set for the autocomplete can get pretty complicated, reaching across multiple models, possibly needing to aggregate, de-dupe data, etc... It sounds like is true of the situation you had as well. Typically users add the Since I don't know your particular use case though; I may be missing something here. |
The only problem I can see with the way I've done it would be possible duplicates if someone searched the same model with multiple methods. Should I implement something to automatically cull duplicate results? |
Refactored to allow search of multiple model/method combinations. Simplifies optional parameters.