M
M
Max2015-11-19 19:41:21
Ruby on Rails
Max, 2015-11-19 19:41:21

How to fetch from a database in rails?

Hello.
Please tell me why it does not work to make a selection from the database?
It is necessary to take all users who have status = true.
I do it like this:

def index
  	@users = User.find_by status: false
  end

<tbody>
    <% @users.each do |user| %>
      <tr>
        <td><%= user.name %></td>
        <td><%= user.surname %></td>
        <td><%= user.age %></td>
        <td><%= user.status %></td>
        <td><%= user.enter_date %></td>
        <td><%= user.doctor_id %></td><code lang="javascript">
</code>
        <td><%= user.diagnoz %></td>
        <td><%= link_to 'Переглянути', user %></td>
      </tr>
    <% end %>
  </tbody>

Throws an undefined method `each' error. At the same time, if you write:
def index
  	@users = User.all
  end

Here already quietly all users are deduced.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrew, 2015-11-19
@maxprof

@users = User.where(status: false)
apidock.com/rails/v4.0.2/ActiveRecord/FinderMethod...
find_by will only return the first value

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question