Creating a menu with use of a dropdown menu

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?

Answers


You're close. When I do faceted searches, I first start by creating an empty array in my controller :

@current_items = []

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 :

params[:faceted_items].each do |item|
  @current_items << Object.where("#{item}" => true)
end

Then call @current_items as 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.


Need Your Help

Error creating bean with name 'org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping'

java spring spring-mvc spring-security

I'm developing a web application with Spring MVC. I started by developing the web application after I'm trying to add Spring Security; but I have this message, and I don't find a solution.

Build works for iOS 7, but crashes in iOS 6

iphone ios6 crash

I've been making an app and only testing in iOS 7 simulator until now, and I wanted to try and build for iOS 6, to see if it looks good. Problem is, I get a mysterious crash when I build for iOS 6....