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>