Lucas Moraes


1,330 Experience
12 Lessons Completed
0 Questions Solved


Nice, @eelcoj and @Ali Ahmed. Thanks for sharing.

To anyone looking for more info about how to work with associated models, here is:

Item.rb (model):

  # Relations
  belongs_to :brand

    ## many-to-many relations between Items and Textures
    has_many   :item_attribute_for_textures
    has_many   :textures, through: :item_attribute_for_textures, :class_name => 'ItemAttribute::Texture'

    # Searchkick

  def search_data
      full_item_title:  full_item_title,
      brand:            brand.try(:title),


  def index
    args = {}
    args[:brand]          = params[:brand]          if params[:brand].present?
    args[:texture]        = params[:texture]        if params[:texture].present?

    query = params[:busca].presence || "*"
    @items  = query, where: args, 
      aggs: { 
          full_item_title:  {},
          brand:            {},
          texture:          {}

and view index.html.erb:

<div class="row">
  <div class="col-sm-2" style="font-size: 0.75rem">

      <% @items.aggs["brand"]["buckets"].sort_by{ |b| b["key"] }.each do |bucket| %>
          <% if params[:brand] == bucket["key"].to_s %>
            <strong><%= bucket["key"] %></strong>
          <% else %>
            <%= link_to bucket["key"], request.params.merge(brand: bucket["key"]) %>
          <% end %>
          (<%= bucket["doc_count"] %>)
      <% end %>

      <% @items.aggs["texture"]["buckets"].sort_by{ |b| b["key"] }.each do |bucket| %>
          <% if params[:texture] == bucket["key"].to_s %>
            <strong><%= bucket["key"] %></strong>
          <% else %>
            <%= link_to bucket["key"], request.params.merge(texture: bucket["key"]) %>
          <% end %>
          (<%= bucket["doc_count"] %>)
      <% end %>


Posted in How to use ActionText in Rails 6 Discussion

Be careful: you shouldn't allow any origin ("*") in your config CORs.

Posted in DataTables Install via Webpacker

Hi, Dan. Still in trouble? I managed to get a demo app running data-tables e others jquery library here:

This demo is running Rails 6 with Webpack and Yarn.

According to the error that you describred at Datatables forum, looks like that you're missing to declare the jquery global variable '$'. Take a look to my environment configs (environment.js, app.js, etc) at the repo above.

Hi, Bozazitz! Thanks for the help out!

Posted in Exporting Records To CSV Discussion

This just helped me 4 years later. Thanks, Chris!

Posted in Open Closed Principle Discussion

fantastic piece of advise!

Posted in Single Responsibility Principle Discussion

Fantastic, Chris! Thanks!

Hi, all.

We has an app with Rails 4.2.5 and Angular 2 integrated (we do not use it very much). But we would like to switch to another JS framework: Vue and Reacth are good options.

But will we have any conflicts since there will be two JS framework working?

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.