forked from JangoSteve/Rails-jQuery-Demo
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modified Comment scaffolding to make CRUD interface all via AJAX.
- Loading branch information
1 parent
ef31ec6
commit ee605fb
Showing
10 changed files
with
52 additions
and
31 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
module CommentsHelper | ||
def new_comment_link | ||
link_to 'New Comment', new_comment_path, :remote => true, :'data-type' => 'html', :id => 'new-comment-link' | ||
end | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<tr class='comment' id='comment-<%= comment.id %>'> | ||
<td><%= comment.subject %></td> | ||
<td><%= comment.body %></td> | ||
<td><%= link_to 'Show', comment %></td> | ||
<td><%= link_to 'Edit', edit_comment_path(comment) %></td> | ||
<td><%= link_to 'Destroy', comment, :confirm => 'Are you sure?', :method => :delete, :remote => true %></td> | ||
</tr> |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<% unless @comment.errors.any? %> | ||
$('#comments').append( '<%= escape_javascript( | ||
render @comment | ||
) %>' ); | ||
$('#new-comment-form-container').replaceWith( '<%= new_comment_link %>' ); | ||
<% else %> | ||
$('#new_comment').find('#error_explanation').html( '<%= @comment.errors.full_error_messages %>' ); | ||
<% 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
$('#comment-<%= @comment.id %>').remove(); |
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,7 @@ | ||
<h1>New comment</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Back', comments_path %> | ||
<div id='new-comment-form-container'> | ||
<h1>New comment</h1> | ||
|
||
<%= render 'form' %> | ||
<%= link_to 'Back', comments_path %> | ||
</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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,14 @@ | ||
<p id="notice"><%= notice %></p> | ||
<table> | ||
<tr> | ||
<th>Subject</th> | ||
<th>Body</th> | ||
<th></th> | ||
<th></th> | ||
<th></th> | ||
</tr> | ||
<%= render @comment %> | ||
</table> | ||
|
||
<br /> | ||
|
||
<p> | ||
<b>Subject:</b> | ||
<%= @comment.subject %> | ||
</p> | ||
|
||
<p> | ||
<b>Body:</b> | ||
<%= @comment.body %> | ||
</p> | ||
|
||
|
||
<%= link_to 'Edit', edit_comment_path(@comment) %> | | ||
<%= link_to 'Back', comments_path %> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,8 @@ | ||
// Place your application-specific JavaScript functions and classes here | ||
// This file is automatically included by javascript_include_tag :defaults | ||
|
||
$(document) | ||
.delegate('#new-comment-link', 'ajax:success', function(e, data, status, xhr){ | ||
$(this).replaceWith(xhr.responseText); | ||
}); | ||
|