Answer the question
In order to leave comments, you need to log in
Is it possible to use toggle! method?
The task is to change the value of the comment attribute by clicking on the link, read => false (by default), read => true. But in this situation , false cannot be returned back when you click again. Found this solution:
Everything works. But how good is this solution? Previously, in none of the projects that I have seen, I have not seen such a method. @comment.update(:read => true)
@comment.toggle!(:read)
Answer the question
In order to leave comments, you need to log in
This method changes the value of the boolean field from the current to the opposite. You can apply it. In fact, it was created for this.
We go into the code and see what this click method does , if you think that you can write better, then write your own :)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question