Skip to content

Commit

Permalink
added raw before RDiscount
Browse files Browse the repository at this point in the history
Signed-off-by: Viduranga Wijesooriya <vpowerrc@gmail.com>
  • Loading branch information
vidurangaw committed Mar 3, 2015
1 parent 0eebb32 commit e1637f2
Showing 1 changed file with 68 additions and 0 deletions.
68 changes: 68 additions & 0 deletions app/views/spectrums/show/_commenting.html.erb
@@ -0,0 +1,68 @@
<a name="comments"></a>
<h3>Comments (<%= @spectrum.comments.length %>)</h3>

<% if @spectrum.comments.length == 0 %><p><i>No comments</i></p><% end %>

<div id="commentlist">
<% @spectrum.comments.each do |comment| %>
<div class="comment">
<a name="comment_<%= comment.id %>"></a>
<b><%= time_ago_in_words(comment.created_at) %> ago,
<% if User.find_by_login(comment.author) %><a href="<%= user_path(comment.author) %>"><%= comment.author %></a> wrote:</b>
<% else %><%=h comment.author %> wrote:</b>
<% end %>
<p><%= raw RDiscount.new(comment.body).to_html %></p>
<% if logged_in? && (current_user.role == "admin" || current_user.login == comment.author) %><p><small><%= link_to '<i class="icon icon-remove-sign"></i> Delete'.html_safe, "/comments/delete/"+comment.id.to_s, :confirm => 'Are you sure?' %></small></p><% end %>
</div>
<% end %>
</div>

<br />

<% if logged_in? %>
<form action="/comment/create/<%= @spectrum.id %>" class="well form" id="commentform" method="post">

<h3 style="margin-top:0;">Post a comment</h3>
<textarea name="comment[body]" id="commentbody" cols="8" rows="6"></textarea>

<br />
<input type='hidden' name='authenticity_token' value="<%= form_authenticity_token %>"/>
<input type='hidden' name='goto' value="analyze"/>
<input id="commentsubmit" class="btn btn-primary" type="submit" value="Post" />

</form>
<script>
jQuery(document).ready(function() {
$('#commentform').bind('submit', function(e){
e.preventDefault()
$.ajax({
url: "/comment/create/<%= @spectrum.id %>",
type: "POST",
data: {
authenticity_token: "<%= form_authenticity_token %>",
comment: {
body:$('#commentbody').val()
}
},
beforeSend: function() {
$("#commentbody").prop('disabled',true)
$("#commentsubmit").prop('disabled',true)
},
success: function(response) {
$('#commentlist').append('<div class="comment"><a name="comment_'+response+'"></a><b>Just now, <a href="/users/<%= current_user.login %>"><%= current_user.login %></a> wrote:</b><p>'+$('#commentbody').val()+'</p><p><small><a href="/comments/delete/'+response+'" onclick="return confirm(\'Are you sure?\');"><i class="icon icon-remove-sign"></i> Delete</a></small></p></div>')
$('#commentbody').prop('disabled',false)
$('#commentbody').val('')
$("#commentsubmit").prop('disabled',false)
},
error: function(response) {
alert("There was an error and your comment couldn't be posted.")
}
})
});

});
</script>

<% else %>
<p><i>You must be logged in to comment.</i></p>
<% end %>

0 comments on commit e1637f2

Please sign in to comment.