L
L
lavezzi12015-09-11 07:39:32
Ruby on Rails
lavezzi1, 2015-09-11 07:39:32

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

2 answer(s)
A
aykc, 2015-09-13
@lavezzi1

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.

T
TyzhSysAdmin, 2015-09-11
@POS_troi

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 question

Ask a Question

731 491 924 answers to any question