Git Product home page Git Product logo

Comments (7)

Draiken avatar Draiken commented on August 26, 2024

Hello

To enable the delete, you have to provide a condition that will run when someone tries to delete a comment. In other words, it's some logic that will either let someone delete the comment or not. To do so, you can make a method in the ApplicationController and add the logic there as follows

comment_destroy_conditions do |comment|
  comment.owner == current_user
end

In this case, it just deletes the comment, if the current_user is the owner of that comment being deleted. If you want a different logic, just change that method. If the method returns true, the comment will be deleted, otherwise not.

As for the replies, the accept_replies must be set to true in the initializer, and you'll also need to restart the server, or the changes won't run.

from opinio.

laetitiamassa avatar laetitiamassa commented on August 26, 2024

ok thanks.
I had made it previously, but it didn't give me anything. Even after restarting the server (accept_replies is by default set as true apparently).

The views work, but not the logic behind it (when I click on delete or reply, nothing happens - I see in the terminal that a GET request is made, but nothing happens).

For delete, I made:

  • in ApplicationController (the same method which was by default in comments_controller)*
    def can_destroy_opinio?
    comment_destroy_conditions do |comment|
    comment.owner == current_user
    end
    end

in CommentsController
I haven't changed anything to the destroy action

  • in the _comment view*
    <% reply = defined?(reply) ? reply : false %>

#mycodeforthe_commentview

<%= link_to t('opinio.actions.delete'), comment_path(comment), :method => :delete, :remote => true %>
<%# this enables only 1 level of replies %>
<% if Opinio.accept_replies && !reply %>
<%= link_to t('opinio.actions.reply'), reply_comment_path(comment), :remote => true %>


    <%= render :partial => "opinio/comments/comment", :collection => comment.comments, :locals => {:reply => true} %>

<% end %>

in the Opinio initializer
I have uncommented the accept_replies line

It might be obvious, but I don't see where I got it wrong to have it working.
Many thanks for your help!

from opinio.

Draiken avatar Draiken commented on August 26, 2024

So, for the delete part, you should just add the comment_destroy_conditions directly into the ApplicationController, not inside another method.

As for the replies, I need some more information to help you there, some logs would help (you can create a gist) so I can tell you why it isn't working.

from opinio.

laetitiamassa avatar laetitiamassa commented on August 26, 2024

ok thanks,

here are the logs for delete (I guess I should definr project in opinio initializer?):

Started DELETE "/comments/84?locale=fr" for 127.0.0.1 at 2013-05-15 22:42:12 +0200
Processing by Opinio::CommentsController#destroy as JS
Parameters: {"locale"=>"fr", "id"=>"84"}
Completed 500 Internal Server Error in 0ms

NoMethodError (undefined method project' for Opinio:Module): app/controllers/opinio/comments_controller.rb:33:indestroy'

and here are the logs for reply (while I see nothing happen either):
Started GET "/comments/84/reply?locale=fr" for 127.0.0.1 at 2013-05-15 22:49:18 +0200
Processing by Opinio::CommentsController#reply as JS
Parameters: {"locale"=>"fr", "id"=>"84"}
Comment Load (0.4ms) SELECT "comments".* FROM "comments" WHERE "comments"."id" = $1 LIMIT 1 [["id", "84"]]
Rendered opinio/comments/reply.js.erb (0.1ms)
Completed 200 OK in 29ms (Views: 12.4ms | ActiveRecord: 2.5ms)

You can find my gist for the opinio initializer here : https://gist.github.com/laetitiamassa/368d8f2e4e4ae4078857

from opinio.

laetitiamassa avatar laetitiamassa commented on August 26, 2024

ok, actually the reply works but when I click on reply, it seems like I have to go back to the primary textarea and type my comment as if it was a whole new comment instead of a reply (with the textarea appearing directly under the comment I'm replying to). I'll try some things to see if I can fix that for me.

The only problem left (delete) seems like it's not linked to the engine, but leads to a (noobs) question: how to apply methods to the Opinio model (comment) and to the opinio.owner ?

here is the gist for comments_controller https://gist.github.com/laetitiamassa/53d87edf141aada48c1b
I don't know how I should define the method 'project' (instead of 'post' initially) to get it working.
Besides, the line 15 (notification mailer) gets me an error when the comment is actually a reply (undefined method 'participants')

Any idea here? Thank a lot!!

from opinio.

Draiken avatar Draiken commented on August 26, 2024

The delete error is probably because you're trying to use a project variable inside the comment_destroy_conditions.
There are ways to override the overall behavior but that's harder and usually not recommended. Remember inside that block, if for instance, that's a comment of a project, you can access the project through the comment by calling comment.commentable.

from opinio.

laetitiamassa avatar laetitiamassa commented on August 26, 2024

hey,

Thanks.
I found what is was: in the line 33 of the comments_controller, I had replaced "model_name" with the actual name of the model (which is "project"). I've put it back to model_name and I don't have the error anymore. :-)

from opinio.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.