Created
February 6, 2012 14:38
-
-
Save smooki/1752465 to your computer and use it in GitHub Desktop.
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
<section class="commentaires clearfix" id="comments_section"> | |
<h3><%= t(:comment) %></h3> | |
<div class="content" id="comments"> | |
<%= render :partial => "comments/comment", :collection => module_instance.comments %> | |
</div> | |
<%= form_for module_instance.comments.build, :remote => true do |c_f| %> | |
<%#= c_f.error_messages %> | |
<%= c_f.hidden_field :commentable_type %> | |
<%= c_f.hidden_field :commentable_id %> | |
<%= c_f.text_area :comment, :id => "new_comment_input" %> | |
<div class="submit"> | |
<%= c_f.submit t(:post_comment) %> | |
</div> | |
<% end %> | |
</section> |
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
class CommentsController < ApplicationController | |
def create | |
comm = params[:comment] | |
# Instanciation du type de classe depuis son Nom en String. | |
commentable_class = Object.const_get(comm[:commentable_type]) | |
com_id = comm[:commentable_id] | |
# instanciation de la Classe commentable | |
commentable = commentable_class.find(com_id) | |
# création du commentaire | |
c =commentable.comments.create!(:comment => comm[:comment], :user => current_user) | |
c.save | |
# recharger les commentaires pour voir les nouvelles entrée concurrentes (autres utilisateurs) | |
commentable.comments.reload | |
respond_to do |format| | |
format.js do | |
#render :partials => "comment", :locals => { :comments => commentable.comments} | |
end | |
end | |
end | |
def delete | |
comm = Comment.find(params[:id]) | |
comm.destroy | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment