I want to create a menu like on this design
A menu where you choose how you sort and which category you want to be in. So when people press “featured designs”, all the iPhone designs with the field “featured” set to true, will be shown. I want people to be able to choose iPad-designs from the drop down-menu and then the featured iPad-designs should show up. I have no idea how to accomplish this though.
Can somebody give me a pointer?
I’m using rails 3.2.2 and mongoid.
MORE INFO
So I have the whole thing up and running at Meer.li. The menu is there and everything. The only thing I need to add, is a dropdown menu (like the ones you see in forms), so I will be able to choose whether I want to see iPhone, iPad, Windows designs etc.
I can create a drop down menu in rails, but how to use it as a way to query (like you do with a regular menu), is a whole other thing.
Model code:
field :featured, :type => Boolean, :default => false
field :project_number, :type => Integer, :default => 0
field :show, :type => Boolean, :default => true
field :full_member, :type => Boolean, :default => false
field :first_design, :type => Boolean, :default => false
field :option, :type => String
default_scope desc(:created_at)
scope :full_member_and_show, where(full_member: true).and(show: true)
scope :not_full_member_and_show, where(full_member: false).and(show: true)
Controller code:
def newest
designs = Design.full_member_and_show
respond_to do |format|
format.html
end
end
So basically I want to add a .and(:option => “iPad”) to the end if the query whenever I choose another item from the drop down menu.
Does it make sense?
You’re close. When I do faceted searches, I first start by creating an empty array in my controller :
Then I start adding items based on the params I’m getting. Now if you want to be really DRY here, you should be naming your Scopes off of the names of the faceted items in your form. Or vice versa, name your scopes, off of the form. In this way you could do something like this :
Then call
@current_itemsas the array of returned items in your view.Update per comments
Faceted Search is a search that can narrowed down by selecting and or selecting against different attributes.
If that’s what you’re looking for, it sounds like you might want to embed a whole search feature. I recommend either sunspot-solr or sphinx. Both do an alright job at the task.