Comments (7)
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.
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.
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.
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:in
destroy'
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.
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.
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.
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)
- Deleted User HOT 2
- undefined method `num_pages' HOT 9
- Override redirect on successful POST HOT 10
- Cancan ability HOT 3
- How can I add a counter_cache? HOT 1
- Pagination Problem HOT 1
- In v0.6 branch missing files HOT 3
- Demo Sites HOT 1
- Problem with using opinio in app with engine HOT 4
- Customize destroy conditions documentation HOT 3
- Anyway to disable Pagination? HOT 4
- How would you "touch" the parent model when creating/destroying a comment? HOT 1
- Reply/Destroy showing up on nested resource comments for owners HOT 2
- Username HOT 2
- unrecognised users? HOT 3
- addon feature for Ancestry like comments HOT 1
- displaying user avatar HOT 1
- Comments Number Count Issue HOT 12
- Comment owner must be valid? HOT 2
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opinio.