Created
March 28, 2012 20:41
-
-
Save mrdanadams/2230354 to your computer and use it in GitHub Desktop.
Updating a DIV with partials after remote AJAX form submit in Rails 3
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$(function() { | |
/* Convenience for forms or links that return HTML from a remote ajax call. | |
The returned markup will be inserted into the element id specified. | |
*/ | |
$('form[data-update-target]').live('ajax:success', function(evt, data) { | |
var target = $(this).data('update-target'); | |
$('#' + target).html(data); | |
}); | |
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def preview | |
# ... do something meaningful here ... | |
render :partial => 'preview', :content_type => 'text/html' | |
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div id="update-container"> | |
... | |
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<%= form_tag({:action => 'preview'}, :remote => true, :'data-update-target' => 'update-container') do %> | |
<%= url_field_tag 'url', nil, :class => 'textinput', :placeholder => 'Paste the link URL here' %> | |
<%= submit_tag 'Submit', :disable_with => 'Please wait...', :class => 'submit' %> | |
<% end %> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There is no such thing as "ajax:completed". How did you make it work ?
i keep getting data of undefined with the code bellow: