Lucas Moraes


1,850 Experience
17 Lessons Completed
0 Questions Solved


Posted in How to use Hotwire in Rails Discussion

Fantastic, Rafe! Thanks so much!

Posted in How to use Hotwire in Rails Discussion

Can someone help me? I'm confused about Hotwire and some of the latest stuff that came out.

1) What is exactly Hotwire does?
2) And how can be it compared to StimulusJS, Stimulus Reflex and Actioncable?

I'm just having dificulties to understand what each of those are and how each can be used.

Thanks in advance.

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?

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.