Skip to content
This repository has been archived by the owner on Feb 24, 2022. It is now read-only.

goodanthony/json-in-views

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

2 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

JSON views

This app shows how you could use JSON to render views.

designs controller

 # GET /designs/new
 def new
   @design = Design.new
   render :json => {:form => render_to_string(:partial => 'form')}
 end

#designs index.html.erb

<%=content_for :javascripts do%>

<script type="text/javascript">

 $(function(){

     $('#new-design').on("click", function(event) {
       event.preventDefault();
       var url = $(this).attr('href');
       $.ajax({
         url: url,
         beforeSend: function() {

         },
         complete: function() {

         },
         success: function(data) {
           $('#designform').html(data['form']);

         }
       });
     });


    $(document).on("click", "#cancel-btn", function(event) {
       $('form').remove();
       //alert("s");
    });

 })



</script>

About

This app shows how you could use JSON to render views.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published