ruby on rails jquery submit a form as js

前端 未结 3 1335
旧时难觅i
旧时难觅i 2021-01-03 07:38

I have this code in my view:

<%= form_for :folder_name, :remote => true, :method => \"get\", :url => {:action 
    => \"show_workflow_list\"}          


        
相关标签:
3条回答
  • 2021-01-03 07:53

    try this

    <%= f.select :foldernames, options_for_select(@folders, @folders.first), {}, {:onchange => remote_function(:method => :get, :url => {:action => 'show_workflow_list'}, :with => 'Form.Element.serialize(this)')}%><br /><br />
    
    0 讨论(0)
  • 2021-01-03 07:55

    It is because you are using the jQuery submit call incorrectly

    Check this article...it worked for me Rails remote form submit through javascript

    0 讨论(0)
  • 2021-01-03 08:14

    On a JS file you should do this :

    $('#foldernames').change(function() {
      $('#folder_name').submit()
    });
    

    And in your controller you should have this :

    def show_workflow_list
      //code here
      render :format => :js
    end
    

    When you change the value, it should submit your form so it should send an ajax request to your controller. Your controller should render a js format and execute your show_workflow_list.js.erb. To check it, you can use a javascript console like firebug.

    0 讨论(0)
提交回复
热议问题