0

I'm looking to refresh the the table "dashboard_categories" when I click submit without the whole page refreshing, this is what I've done so far: http://pastie.org/7822560

I'm now stuck on what I do with Javascript as I'm a complete novice. I know I have to catch the form submission, send the data and then call the partial to refresh... but have no clue how. Any ideas?

Hopefully I'm not far off...

I've got a content_for tag for the javascript on index.html.erb:

<% content_for :javascript do %>
  <script type='text/javascript'>

  </script>
<% end %>
fotanus
  • 19,618
  • 13
  • 77
  • 111
Taylor Williams
  • 256
  • 4
  • 22

1 Answers1

2

Include unobtrusive javascript driver in your manifest app/assets/javascript/application.js:

//= require jquery_ujs

And then mark the form to be submitted by AJAX:

<%= form_for(@category), remote: true do |f| %>
sites
  • 21,417
  • 17
  • 87
  • 146
  • Thank you!!!!! This is exactly what I was after, just a dumb moment. Now.. how do I go about loading the partial within the div on submit? – Taylor Williams May 13 '13 at 13:35
  • Ok, create.js.erb is rendering correctly. However I need it to reload the div "#dashboard_categories" with the data from create.js.erb? – Taylor Williams May 13 '13 at 14:00
  • I've released create.js.erb is being called and loaded - however it's not rendering with the very latest data? If i submit the form twice, then the second last item shows in the table. – Taylor Williams May 13 '13 at 14:06
  • I've opened a new question here... http://stackoverflow.com/questions/16524506/unobtrusive-javascript-not-loading-latest-submitted-data – Taylor Williams May 13 '13 at 14:29