Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

118
Visualizações
Finding specific type of user in rails app, postgresql

I´m learning ROR by building an app. In my user.rb model I have a four type of users every user can select on Sign up using f.select on the sign up view.

The problem is if I would like to, for an example know How many users are in the industry type 'Heavy' ? Or What is the average :staffcount for the users in the Medium class? I´m not sure how to do that.

This is what I got so far to find the numbers of users in the Heavy class @heavy_users = User.where(industry_type: 'Heavy']).count but with no luck.

can someone be so kind and help me with this?

user.rb
class User < ActiveRecord::Base
# Include default devise modules. Others available are:
# :confirmable, :lockable, :timeoutable and :omniauthable
devise :database_authenticatable, :registerable,
     :recoverable, :rememberable, :trackable, :validatable

     INDUSTRY_TYPES = [['Heavy'], ['Medium'], ['Light'], ['Dirty']]
end

here is the the new.html.erbform for the sign up:

<h2>Sign up</h2>

<%= form_for(resource, as: resource_name, url: registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>

<div class="field">
 <%= f.label :username %><br />
 <%= f.text_field :username, autofocus: true %>
</div>
<div class="field">
 <%= f.label :email %><br />
 <%= f.email_field :email %>
</div>

<div class="field">
 <%= f.label :staffcount %><br />
 <%= f.number_field :staffcount %>
</div>

<div class="field">
 <%= f.label :industry_type %>
 <%= f.select(:industry_type, options_for_select(User::INDUSTRY_TYPES)) %>
</div>

<div class="field">
 <%= f.label :password %>
 <% if @minimum_password_length %>
 <em>(<%= @minimum_password_length %> characters minimum)</em>
 <% end %><br />
 <%= f.password_field :password, autocomplete: "off" %>
</div>

<div class="field">
 <%= f.label :password_confirmation %><br />
 <%= f.password_field :password_confirmation, autocomplete: "off" %>
</div>

 <div class="actions">
  <%= f.submit "Sign up" %>
 </div>
over 4 years ago · Santiago Trujillo
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda