Advanced Search in Rails 5 with checkbox - ruby-on-rails

I'm trying to make an advanced form in Rails.
I have two tables: Category and Tip. Each Tip has several Categories, and a Category can have several Tips. All relationships are done correctly (checked in console).
My goal is to create a form where a user can search for Tips according to one (or more) categories he has selected. I would like to do this in the form of a check box.
Do you have a tutorial to recommend? I'm trying to find some, but either they're under an old version of Rails with obsolete functions, or it doesn't meet my request.
After that, I would like to combine several search criteria (by city, by price range etc.).

Related

Rails associations when unique and common models combine

First of all, I want to apologize for my terminology. I am not entirely sure what to call what I am looking for, so I can’t google for answers. But here is my problem.
I am working on a Rails application that stores information about different websites and provides various services for them. I will call these services ‘Products.’ One website can be subscribed to several products, and a product can be served to various websites. So here is a very simple association scheme for these relationships:
At least, it would have been simple, but the problem is that the Settings model (shown in red on this diagram) is different for each product: for one product, it will have one number of fields and data types, for another it will have a different number of fields with different data types. On the other hand, the Faq and Description are the same, so if I redraw the diagram as follows:
I will get another problem: too much repetition (shown in blue on the diagram). Ideally, I want some kind of modification of the first diagram, where the Product model will choose differens Settings models depending on a parameter that I pass to it:
So that a request website.products.find(1).settings will return the model Settings1, while a request website.products.find(2).settings will return a completely different model, Settings2.
Is this achievable in Rails? If not, how would you organize such data?

What is the best way to add a list of 'skills' to a user model in rails?

On my User's edit page I want users to be able to select from checkboxes what programming languages they know. I will give them about 15 to choose from. I then want to store these results in the User model to be accessed/searched for later.
What is the best way to go about this?
You can apply a many to many associations for achieving so. If you Google or even search SO, you will get lots of examples.
However, you can simply achieve same thing using the following gem
https://github.com/mbleigh/acts-as-taggable-on
It appears it's example matches your requirements. In the examples, they described same (skills) thing. So, you will get it done easily.

Filtering Database results in Ruby on Rails

I have created a rails application where users can create and apply for jobs.
As you can imagine many of these jobs come from various countries/cities and have different salaries and industries etc. I would like to create a system that will allow my users to filter through all the options to find what they're most interested in.
I would like to use a combination of radio buttons and a salary slider bar (probably Jquery) in my view to select the results that show. I would then like the page to reload (without refreshing - like AJAX) when the user hits a button called filter results.
A good example of the kind of filtering system I would like to achieve can be seen at WIWT.com if you just click on their top filters button they have an excellent filtering system.
It would be great to know where to get started on this and whether there are any easy to use Gems already out there? Also if anyone could point me in the direction of a thorough tutorial that would be great as much of what I have found has been fairly incomplete and based around has_scope.
Thanks!

Rails 3.1 interface design - Cascading dropdown, form input

For a case where I have models like:
Coutries
States
Cities
Opinions
I'd like to begin with just presenting a user with a dropdown for Coutries.
Once a country is selected, then a States dropdown would appear below Countries.
Once a State is selected, then a Cities dropdown would appear below States.
Once a City is selected, a textboxt appears and the user writes their opinion of the city.
Once text is placed in the textbox, a 'submit' button appears.
Once the user clicks 'submit' I process the form data.
I'd like to populate each dropdown from a corresponding table using the previous selection to limit the dropdown items.
I'd like the same sort of functionality with checkboxes too.
Basically, I'd like to be able to define a cascading form input scheme. I have seen some information on the topic, but nothing that wraps it up tight for Rails 3. For instance:
Rails 3.1 Dependent / Cascading Dropdowns and
Rails 3.1 interdependent select dropdown lists
... seem to offer only partial solutions. I am getting the feeling that I might be missing some fundamental Rails concept and that this (seemingly common) task should be easier. I want to streamline the user input experience. My models have a lot of good default data that I'd like to present to the user as they make their input choices. I just can't seem to get it all on one page.
I don't get the search results I am seeking when I look for "Rails dynamic form input" Searching for "Rails Cascading dropdown" has helped some. "Rails active form" gets me a piece of internet history.
Can someone guide the way?
Thanks!
ADDENDUM
This seems to allude to the trouble I have stumbled upon: http://guides.rubyonrails.org/form_helpers.html#building-complex-forms Perhaps that's my answer?
JQuery is the way to go here I think. Now I am no expert in matters pertaining to JQuery, but I hope I can at least point you in the right direction. To accomplish your cascading list, you could show and hide the select inputs based on the change of the previous one. From there I would look into a JQuery library called jquery-chained. This library would allow you to show in the states select only those states which pertain to the selected country. I do have a couple working examples of the chained library that I could show an example of if you would like, and I am sure there are many examples out there of hiding and showing form elements in JQuery.

Populating dropdownlists for mult-tenant applications

I am building an mvc 3 application that will be multi-tenant, which means it will use the same basic data structure, but provide different data depending on the domain name used to access it.
A problem I am trying to solve is this. How best do I populate a number of dropdown lists with selection choices based on the site being rendered. To add another wrinkle, I will need to localize the strings as well.
An obvious choice is to simply create a table with columns for website id and language id, plus field id and string value. This seems ok, but also seems to ignore possible mechanisms that are already in place for localization. I feel like i'm recreating the wheel here.
As an example, site 1 might have a dropdownlist for Favorite Activities, and have ranges items that are geared toward musical interests. Site 2 might have the same dropdown, but have items geared for sports intersts.
So my question is, how would you go about solving this problem? Also, in a similar vein... If you have selection lists, say State codes, cities, etc.. would you tend to create seperate tables to populate this data (states table, cities table, etc..) or would you put all this information in a common table and have an ID to indicate which dropdown it was to be used for? The former seems more normalized, but the latter seems more efficient (less code to write).
Thoughts about Common Lookup Tables. This guy is definitely against.
http://www.projectdmx.com/dbdesign/lookup.aspx
I have used it and believe that I have saved some time, or at least some keystrokes. Might be sorry later on.

Resources