Answer the question
In order to leave comments, you need to log in
Understanding Variables in Rails?
Stumbled upon a problem while trying to put objects with certain qualities into variables
tasks_controller.rb:
(Rails 4)
def index
@incomplete_tasks = Task.find_by(status: 0)
@completed_tasks = Task.find_by(status: 1)
end
<% @incomplete_tasks.each do |task| %>
...
<% end %>
Answer the question
In order to leave comments, you need to log in
find_by
returns a single record either nil
Try, for example, Task.where(status: 0)
And use named scopes.
scope :completed, -> { where(status: 1) }
scope :incompleted, -> { where(status: 0) }
And access them: Task.completed, Task.incompleted
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question