How to use a specific controller \ action on "onchange" for Select_tag in ruby ​​on rails

I knew about MVC and Ruby on rail environment I have this code <%= select :language, :language_id, options_for_select([ "Arabic", "English"]), {:prompt => "#{t('language')}"}, {:onChange => "#{remote_function(:url => {:controller => 'ConfigurationController',:action => "change_language"} )}"} %> And I can’t do Select to trigger this action and make PostBack for the page turned on when changing

nothing happens after the selected index change?

+3
source share
2 answers

What version of Rails are you using? It looks like remote_function has been broken into 3.1 http://apidock.com/rails/ActionView/Helpers/PrototypeHelper/remote_function

Use jQuery to respond to a change event:

jQuery ->
  $("#select_id").change ->
    $.ajax(
      url: "url",
      dataType: "json",
      data: "data to send")
        .done (data) ->
          do_something_on_success()
        .fail (data) ->
          do_something_on_fail()
0
source

. , , .

select_tag, .

Edit:

- onchange? .

 <%= select_tag "language", options_from_collection_for_select(@collection,'value','name'), html_options = { :onChange=> "alert('');" :style=> "display:block;" } %>

u ,

@collection = ["en","ab"]
@collection = @collection.map { |name, value| OpenStruct.new(:value => name, :name => name) }
+1

All Articles