Praveen KJ
Praveen KJ

Reputation: 650

rails fetching only true boolean objects in model instance variable

I am currently fetching all notes in model by

@notes_list = current_user.notes.order(:title).group_by { |note| note.title[0] }

Later i added a column to notes table that is known a boolean column.

Now i want to fetch only true valued columns and false valued columns separately something like below

@notes_true_list = blah....
@notes_false_list = blah....

Can anyone help me?

Upvotes: 2

Views: 64

Answers (1)

Pavan
Pavan

Reputation: 33542

Try the below code.

@notes_true_list = current_user.notes.where(known: true).order(:title).group_by { |note| note.title[0] }

@notes_false_list = current_user.notes.where(known: false).order(:title).group_by { |note| note.title[0] }

Upvotes: 2

Related Questions