Rails: Preselect Option from dropdown menu -


i have working filter on table, want preselect 1 of filters according in team user is. code filter following

<%= form_tag request.path, :method => 'get' %>       <%= select_tag "filter", options_for_select([ "alle", "men", "women", "juniors" ],  params[:filter]), class: 'my_filter'%> <% end %> 

now every user belongs 1 of 4 groups, in user db identified team_id if open page want select according fitler each user default.

thank help

edit:

working js update code

<script type="text/javascript"> $(function(){     $('select.my_filter').on('change', function(){       alert($(this).val())     $(this).closest('form').submit()     }) }) 

options select accepts selected option:

options_for_select(["alle", "men", "women", "juniors"], selected: "men") 

see http://apidock.com/rails/actionview/helpers/formoptionshelper/options_for_select

in general can use form builders simple_forms or formtastic select options according model attributes.


Comments

Popular posts from this blog

java - Oracle EBS .ClassNotFoundException: oracle.apps.fnd.formsClient.FormsLauncher.class ERROR -

c# - how to use buttonedit in devexpress gridcontrol -

nvd3.js - angularjs-nvd3-directives setting color in legend as well as in chart elements -