SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Member
    Join Date
    Oct 2012
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    How to create an advanced search form

    Hello,

    I am a newbie in using Ruby. I am having issues with the form that I am going to use. I always get errors in using form_for tags. I am trying to create this sort of advanced search form: http://www.celiac.com/glutenfreemall...ced_search.php, I want to create the same form like the site shows. I am also having issues with using f.check_box or is it still applicable. Sorry for my mistakes in doing it, I am really a newbie in Ruby. Hoping for your responses.

    Please help me in my project. Thanks.

    Marychris

  2. #2
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,312
    Mentioned
    178 Post(s)
    Tagged
    8 Thread(s)
    Hi there,

    If you want to make an advanced search form using Rails, then I recommend Sunspot/Solr.
    Sunspot is a standalone Ruby library which integrates with the Solr search engine. It wraps the indexing and querying of the database in a declarative DSL, which you can use to expose virtually any Ruby object to be searched (not just ActiveRecord models). The sunspot gem also bundles a standalone version of the Solr search engine, which is great for your dev environment.

    Here are some resources to get you started:
    Railscast: http://railscasts.com/episodes/278-search-with-sunspot
    Sunspot homepage: https://github.com/outoftime/sunspot
    Sunspot Wiki: https://github.com/sunspot/sunspot/wiki
    Sunspot API documentation: http://outoftime.github.com/sunspot/rails/docs/
    A Rubysource tutorial: http://rubysource.com/flexible-searc...r-and-sunspot/

  3. #3
    padawan silver trophybronze trophy markbrown4's Avatar
    Join Date
    Jul 2006
    Location
    Victoria, Australia
    Posts
    4,095
    Mentioned
    28 Post(s)
    Tagged
    1 Thread(s)
    Sunspot / Solr is a great tool but I think it may be overkill for this case.
    It's brilliant for fulltext searching and filtered results but requires running another database server.

    One of simplest ways I've found is using the Ransack gem http://railscasts.com/episodes/370-ransack

    The trick with understanding those form helpers is that there are two versions.

    form_for :blah binds a form to the :blah model and expects all fields to be attributes on the model.
    A search form doesn't work that way ( you don't have a 'search' attribute on a model )
    All the form helpers not using a model end with the word 'tag' e.g. form_tag, checkbox_tag etc. and will just create form tags and pass through values without expecting anything to do with a model.

    I'd suggest watching one of the earliest railscasts on a simple search form http://railscasts.com/episodes/37-simple-search-form and then using ransack for the more advanced one.

  4. #4
    Gre aus'm Pott gold trophysilver trophybronze trophy
    Pullo's Avatar
    Join Date
    Jun 2007
    Location
    Germany
    Posts
    5,312
    Mentioned
    178 Post(s)
    Tagged
    8 Thread(s)
    Quote Originally Posted by markbrown4 View Post
    One of simplest ways I've found is using the Ransack gem http://railscasts.com/episodes/370-ransack
    Oh nice. I hadn't heard of this. Thanks for the tip.

  5. #5
    SitePoint Member
    Join Date
    Oct 2012
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for info. It really helps me much...


Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •