Stan X


2,660 Experience
7 Lessons Completed
2 Questions Solved


Posted in How do I switch from 1 database to 1 database per client?


Posted in How to monitor account progress?


Posted in Search Filters with ElasticSearch Aggregations Discussion

Hi Guys/Chris.

1.I am strungling to have this work in parallel with a search input. not sure how to write the query to avoid intereference with the buckets.

2.Also, similar question but this time with Pundit. Where to incorporate the policy_scope(Model) to allow restriction based on usage rights?

3) Last but not least, in the checkbox_tag used by Ken Beegle (above), how to you retain the checkbox value after that the user can understand what he/her has selected.

many thks in advance ;-)

Posted in Search Filters with ElasticSearch Aggregations Discussion

Hi Ken. Did you manage to keep the checkboxes checked after form submission??

Posted in Current_account selection

I finally went for 1 with Current.account implementation (a few days banging head). it works about ok....I have a lot of workarounds though...closing this. feel free to comment if you need some input. (PS: be part of the community).

Posted in Current_account selection

So far, I have applied the Current.account as described in this other episode ( ).

However, not sure how to populate a dropdown idem for shifting this Current.account (meaning to modify script name).

 <select  id="mySelect">
         <% current_user.accounts.order(name: :asc).each do |account| %>
                             <%= link_to(,  params.to_unsafe_h.merge(script_name:>
         <% end %>

the above does not shift anything.

Not sure this is the direction i should take (option 1 in my question above).

Posted in Current_account selection

here is my model setup:
has_many :account_users
has_many :accounts, through: :account_users
has_many :account_users
has_many :users, through: :account_users
belongs_to :account
belongs_to :user

Posted in Current_account selection

Hi Guys,

In the app I am building, my users have several accounts (though account_users).
For each account they can create, view, update... articles
I would like to have a global selector at the top to pick the account.
Selecting the account would propagate to views, actions....

  1. I tried the current on rails 5.2
    (Rails 5.2 ActiveSupport CurrentAttributes) described in a screencast but was not sure how to modify the params through a dropdown as this is outside of a model form.

  2. As an alternative to a global current_account (which solution I am not capable of doing right know), I was also thinking of creating an additional attribute for the user model like ’selected_account’ as this might ease for changing through a form. but I can see this might not be the way to go if the link is sent across users.

Also, I wanted to avoid carrying the account id in the url as params unless it is much much simpler (or mandatory). but doing this might be a trouble when you share link between users….so I’ll go for the simplest solution (1, 2 or else).

Posted in How to Add Pagination with Pagy Discussion

And the pagination from pagy does not work anymore...:-(

Think I have an issue. Appreciate is someone could help to combine 3 things:

  • pagy
  • searchkick
  • pundit probably never heard off outside Gorails but Chris is introducing too much nice gems. Question: how to make them work together.

Posted in How to Add Pagination with Pagy Discussion

following this note from Stephen Dolan, I did something which provides the results be fair it is dirty...(and i don't know what i am doing!)

query = params[:search].presence || "*"
@pagy_s, @employees = pagy_searchkick (
    misspellings: {fields: [:department]},
    order: {created_at: :desc},
    load: true,
    per_page: 40,
    scope_results: ->(r) { r.where(id: policy_scope(Employee).pluck(:id)) }


Posted in How to Add Pagination with Pagy Discussion

@pagy_s, @employees = pagy_searchkick (
    misspellings: {fields: [:department]},
    order: {created_at: :desc},
    load: true,
    per_page: 40

        I have some results. trouble is that my policy_scope from pundit does not apply anymore if i do this.

Posted in How to Add Pagination with Pagy Discussion

Hi chris, Domizio,

I have not managed to get pagy to work with searchkick (implemented as the searchkick episode). getting weird message as it seems to be looking for a total_count method. I am in Rails 5.2. Thks much for your help.

Posted in Setup MacOS 10.14 Mojave Discussion

for readers willing to upgrade it might be a bit different. in particular if you were using rvm which is not compatible with rbenv. I could not understant why installing a new ruby version with rbenv was still linking to a previous one installed with rvm. So to sumarize: go for the installation from Chris above if you are starting from scratch...but follow this if you are coming from another world ;-)

Posted in Build Multitenancy App in a different way

when i say 'accounts' it can be companies, schools, it ;-)

Posted in Build Multitenancy App in a different way

I have seen many questions and topics in gorails about multitenancy but I am a bit undecided about which way to go. 

I would like my app not to carry the subdomain name in the url. Indeed, I would like users to be able to switch between several accounts as long as he has been entitled by the admin of the account (subdomain). So user A can be admin of X, Y and be simple user of Z (entitled by another admin). Permission would be read from a central place - dedicated database?- and visibility/edition/destruction of content items (eg. contacts, files...) would be based upon these rights. Ideally - but that would be the cherry on the cake - each account and content items- would be insulated in different databases- the reasons for this is that i could read some info into different storage places (in a far far future) - including locally. 

Turning over to GoRails community and Rails experts. feel free to join the discussion. 

Posted in add index to nested forms

Seems strange to me. In the meantime, I found a workaround using CSS.

this is the top of my sub-form:
<section><%= f.label :label, class:'info col-md-4 col-form-label'%></section>

and this is the CSS added:

body {
  counter-reset: section;
section {
  counter-increment: section;
  white-space: nowrap;
  overflow: hidden;
section label:after {
  content: ' ' counter(section);

Posted in add index to nested forms

thks Jack.

I changed it for:

  <%= render partial:'profile_fields', locals: {f: profile_form, i: profile_form.index}%>

but receiving a

undefined local variable or method `i' for #<#Class:0x,...
for my subform line:

    <%= f.text_field :label, class: "form-control", placeholder: "Profile #{i}" %>

presumably profile_form.index is not defined ?

Posted in add index to nested forms

Hi guys.

currently struggling to retrieve child index reference in nested forms.
I have my main form:

<%= form_for(resource, as: resource_name, url: registration_path(resource_name), html: { method: :put, class: 'form-horizontal' }) do |f| %>
<%= render 'shared/devise_errors' %>
<div id="profiles">
            <%= f.fields_for :profiles do |profile_form| %>
                <%= render 'profile_fields', f: profile_form%>
    <div class="actions">
  <%= f.submit "Enregistrer", class: "btn btn-primary float-right" %>
<% end %>

and sub form _profile_fields.html.erb:

<div class="card text-justify" >

  <div class="card-header">
    <h4 class="card-title">
      <%indexi = f.options[:child_index].to_i+1 %>
      <%index= indexi.to_s %>
      <div class="form-group row">
        <%= f.label :label, class:'info col-md-4 col-form-label'%>
        <div class="input-group col-md-8">
          <%= f.text_field :label, class: "form-control", placeholder: "Profile #{index}",:value:(f.object.label || "Profile #{index}") %>


this index is stuck to same figure when I add some new profile forms (child of user).

I probaby have to refactor but unclear how. seems to me that many have experienced a similar issue in the past. answers not really clear. is there anything missing in rails to be able to do this in an easy way?

Posted in Companies / Employees / Products

Hi GoRails friends,

I have a list of products. Products can be created by users. So far so good.

Now, I would like to allow some users to be part of companies (0, 1 or several).
One user (the admin for the company) to invite users to be 'part' of his/her company.
When part of the company, the user will be able to create products on the name of the companies he/she belongs to (in addition to create products on his/her own but that somehow a detail).

Not sure how to split this out to start - including using gems like invitable (examplified by Chris) for the invitation system.


Hi Chris. yes! all day events and multi-day events (in case this is different).

Screencast tutorials to help you learn Ruby on Rails, Javascript, Hotwire, Turbo, Stimulus.js, PostgreSQL, MySQL, Ubuntu, and more.

© 2024 GoRails, LLC. All rights reserved.