Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Question: Create comment from controller #154

Open
mohamed-benali opened this issue Nov 19, 2019 · 2 comments
Open

Question: Create comment from controller #154

mohamed-benali opened this issue Nov 19, 2019 · 2 comments

Comments

@mohamed-benali
Copy link

How can i create a comment from a controller.
I want to create a comment each time i edit a post(the comment needs to be attached to the thread of the post i edited).
The documentation don't say anything abot creating a comment from the code. How should i do it?

@Dantemss
Copy link
Member

You can do something like https://github.com/lml/commontator/blob/master/app/controllers/commontator/comments_controller.rb#L37-L39
You can get the thread with object.commontator_thread

Other lines in this method are access control (which you probably already handle yourself), subscriptions and comment nesting, which you may not need.

@mohamed-benali
Copy link
Author

mohamed-benali commented Nov 19, 2019

Thank you

Just for completness im gonna post how its done.

I putted this code on my post controller

# Code
@commontator_thread = @post.commontator_thread
@commontator_user = User.find(session["logged_user"]) 
@comment = Commontator::Comment.new(
    thread: @commontator_thread, creator: @commontator_user, body: "message text"
)
if @comment.save
    # Code
end

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants