Samantha O


1,290 Experience
3 Lessons Completed
1 Question Solved


Posted in Get started with Rolify for roles

@excid3 @Chris Oliver, I was wondering if you can still make this happen :D

Posted in What is the best way to work with user roles?

So the question is, how do I make separate signups for store_owner and end_user? An example of this would be something like airbnb...There you can be a host (someone who rents out their home, or someone who rents a home from a host).

Posted in What is the best way to work with user roles?

What is the best way to achieve this when people sign up? I have a user model and an account model. I want to have 3 roles in my application. The administrator, store_owner and end_user.

A store owner can add a store.
The end_user sees all the stores that a store_owner has added.
The administrator sees everything :)

For now I have:

  class User < ApplicationRecord
  devise :database_authenticatable, :registerable,
  :recoverable, :rememberable, :validatable

  enum type: [:administrator, :store_owner, :end_user]
  enum gender: [:male, :female]

class Account < ApplicationRecord
  enum status: [:active, :inactive, :expired, :locked]
  has_many :users

  before_create :set_api_key
  accepts_nested_attributes_for :users

  def self.generate_api_key

  def set_api_key
    self.api_key = Account.generate_api_key

And in my signup view:

<%= form_for @account do |f| %>
<%= f.fields_for :users do |user| %>
<%= f.label :email %>
<%= user.email_field :email, autofocus: true, autocomplete: "email", placeholder: "[email protected]" %>
<%= f.label :password %>
<% if @minimum_password_length %>
    <em>(<%= @minimum_password_length %> characters minimum)</em>
<% end %>
<%= user.password_field :password, autocomplete: "new-password", placeholder: "Password" %>
<%= f.label :password_confirmation %><br />
<%= user.password_field :password_confirmation, autocomplete: "new-password", placeholder: "Password" %>
<%= f.submit "Sign up" %>

In my accounts controller:

class AccountsController < ApplicationController
  def index

  def new
    @account =

  def create
    @account =

      sign_in @account.users.first, bypass: true
      redirect_to root_path
      render :new

  def destroy
    @account = Account.find(params[:id])
    redirect_to root_path, notice: "Account deleted."


  def account_params
    params.require(:account).permit(users_attributes: [:email, :password, :password_confirmation])

It works!
I had to add a form_for block in the view and pass the pricingclassification object.

<%= form_for :pricing_classification do |f| %>
        <%= f.label :pricing_classification %>
        <%= select_tag nil, options_for_select(range_options, range_string(, data: { action: "change->range#change" } %>
        <%= f.hidden_field :minimum, data: { target: "range.minimum" } %>
        <%= f.hidden_field :maximum, data: { target: "range.maximum" } %>
        <% end %>

I have a Store model and a PricingClassification model. The PricingClassification belongs to Store. I have made a wizard for creating a store and I am trying to add a range in pricingClassification. But I get the undefined method `minimum' for #Store:0x00007fb25c749b20
What am I missing or doing wrong?

class Store < ApplicationRecord
  has_many :pricing_classifications, dependent: :destroy

class PricingClassification < ApplicationRecord
  belongs_to :store

module PricingClassificationsHelper
      def range_string(pricing_classification)

While creating a new store I have this in my view.
<%= f.label :pricing_classification %>
<%= select_tag nil, options_for_select(range_options, range_string(f.object)) %>
<%= f.hidden_field :minimum %>
<%= f.hidden_field :maximum %>

Posted in How do I add ranges to my application?

Awesome! I also send you a slack private message for 2 screencast ideas :S Thank you

Posted in How do I add ranges to my application?

Do you have an example of number 2? I'm fairly new to programming :S

Posted in How do I add ranges to my application?

Hi Chris,
Thanks for the reply. How do I get this in a dropdown? Like this example:

I sure hope Chris will do this soon :)

Posted in How do I add ranges to my application?

Hi in my app I want to have a price classification table where I want to add a range per person...
For example: range_per_person = 1-10, 11-20, 21-30 etc etc.
How can I achieve this? See my schema below.

create_table "pricing_classifications", options: "ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_0900_ai_ci", force: :cascade do |t|
t.string "name"
t.integer "range_per_person"
t.datetime "created_at", precision: 6, null: false
t.datetime "updated_at", precision: 6, null: false

Hi Chris,
I added English and Dutch translations, but when I switch to Dutch(nl), I don't see the translations...Any idea where I might have gone wrong? In the nl.yml file the first line is nl:
Thanks in advance

Thanks Tim, I will have a look at it :)

Hi Tim,
Thanks for the reply, can you provide me with a link to the stimulusjs-components of Chris? Thanks!

Hi GoRails,

I would like to make a multistep wizard in ruby on rails without making use of the wicked gem. Just stimulusJS and ruby :)
Could you make a tutorial about that?

Thanks in advance!

logo Created with Sketch.

Ruby on Rails tutorials, guides, and screencasts for web developers learning Ruby, Rails, Javascript, Turbolinks, Stimulus.js, Vue.js, and more. Icons by Icons8

© 2020 GoRails, LLC. All rights reserved.