Filter select fields based on previous select fields values

Previous Topic Next Topic
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
Report Content as Inappropriate

Filter select fields based on previous select fields values

Guilherme Arruda

Hi everyone, I'm new at RoR and I'm having a trouble in my app. The problem consists on filter a select field named "Solution", based on the others select fields above it. The attached image shows an example of these fields.

Now, what the app do is to retrieve all information from BD abaout Area, Region, Associated, Solution and populate the select fields with these data. But the user wants that, when an area, a region and an associated is selected by the user, only the solutions about that associated in that region on that area should be shown. I know there is a way to do this with AJAX and JS, but I would like to do this with ruby only, in order to keep code clean and correct. Here is my controller code which populates the select fields:

def populate_selects
       @atendiment_area_users = AtendimentAreaUser.where(status: true, user_id:
       @atendiment_region_users = AtendimentRegionUser.where(status: true, user_id:
       @atendiment_region_associated = AtendimentRegionAssociated.where(status: true, entity_id: current_user.entity_id).where(atendiment_region_id:
       @solution = Solution.where(entity_id: current_user.entity_id, status: true)

Below, the _form.html.erb code from view:

    <div class="field">
    <div class="row">
      <div class="col-xs-6">
        <%= :atendiment_area_user_id , @atendiment_area_users.collect { |c| [, ] }, {:prompt=>"Area"}, { :class => 'form-control', :required => true } %>
      <div class="col-xs-6">
        <%= :atendiment_region_user_id , @atendiment_region_users.collect { |c| [, ] }, {:prompt=>"Region"}, { :class => 'form-control', :required => true } %>

    <div class="field">
        <%= :atendiment_region_associated_id , @atendiment_region_associated.collect { |c| [, ] }, {:prompt=>"Associated"}, { :class => 'form-control', :required => true } %>
      <div class="field">
        <%= :solution_id , @solution.collect { |c| [, ] }, {:prompt=>"Solution"}, { :class => 'form-control', :required => true } %>

I've tried to use the AJAX remote: true on form_for, but it didn't worked.  If anyone can help, I apreciate. Thx for attention and sorry any bad english..

You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
To post to this group, send email to [hidden email].
To view this discussion on the web visit
For more options, visit