Created
October 6, 2011 07:36
-
-
Save deepakdargade/1266767 to your computer and use it in GitHub Desktop.
Rails 3 put data through jquey ajax
This file contains hidden or 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
| In gemfile add, | |
| gem "json" | |
| In javascript file, | |
| var path ="/branches/8/student/154; | |
| $.ajax({ | |
| type: "PUT", | |
| url: path, | |
| data: { student : JSON.stringify( {name : "deepak", last_name : "dargade"} ) }, | |
| dataType: 'json', | |
| success: function(msg) { | |
| alert( "Data Saved: " + msg ); | |
| } | |
| }); | |
| In controller, | |
| def update | |
| params[:student] = JSON.parse params[:student] if params[:student].is_a? String | |
| .... | |
| .... | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment