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/advanced_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.
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:
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-searching-with-solr-and-sunspot/
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.
Oh nice. I hadn’t heard of this. Thanks for the tip.
Thanks for info. It really helps me much…