问题
I'd like my date to get saved anytime I change my date via ajax, is this possible? I tried
<%= form_for @dates,:remote => true do |f| %>
<%= f.date_select :booking_date,:onchange => "this.form.submit();" %>
<% end %>
but it does nothing, any good work arounds?
回答1:
From the rails documentation:
date_select(object_name, method, options = {}, html_options = {})
Because onchange is an html option you need to provide an empty set of options to date_select, otherwise it assumes onchange is a date_select option.
You should change your call to date_select to look like this:
f.date_select :booking_date, {}, :onchange => "this.form.submit();"
回答2:
Are you including this in your layout:
<%= javascript_include_tag :defaults %>
<%= csrf_meta_tag %>
来源:https://stackoverflow.com/questions/6566711/rails-3-ajax-date-select-onchange-submit