title: The method .joins() must contain arguments (Syntax problem from Rails v4.2.1 to Rails v6.1.3.1)
body: <p>I have been working on an App called CtrlPanel for the company I work for.
  This app was originally running on Ruby v2.2.2 and rails v4.2.1.  I could not get that environment to work on ANYTHING; I tried both PC and Linux.  Since I couldn't get that environment running and since it needed to be updated to the newest version anyway I figured I would just get it working on the latest version.</p>
  <p>I had no idea what I was in for, that was a little over a month ago.  I am happy to report I now have everything in the program working with one exception.  There is a catalog that displays all of the items and it uses a scope in the model with a lambda expression that is rather complicated (at least to me).  I have had to update the syntax ALL over this application due to the older version of Rails and now being on the newest version and this is the only one I can't seem to figure out. I am pretty sure again that it is just a Syntax problem from Rails v4.2.1 to Rails v6.1.3.1 but I just can't seem to figure it out and I am sure people who are more experienced than myself will know what it is.</p>
  <p>Here is the model in question:</p>
  <p>category.rb</p>
  <pre><code># == Schema Information
  #
  # Table name: categories
  #
  #  id         :integer          not null, primary key
  #  name       :string(255)
  #  created_at :datetime         not null
  #  updated_at :datetime         not null
  #
  
  class Category &lt; ActiveRecord::Base
    attr_accessible :name
  
    # accepts_nested_attributes_for :product_categories
  
    has_many :products, through: :product_categories
    has_many :product_categories, dependent: :destroy
  
    default_scope { order(&quot;id&quot;) }
    scope :with_published_products, -&gt; { joins{product_categories.product}.where{products.status.eq &quot;published&quot;}.uniq }
    scope :with_matched_search_terms, -&gt;(search_terms) { joins{product_categories.product}.where{products.name.like search_terms}.uniq }
  end
  </code></pre>
  <p>The line with the issue is:
  scope :with_published_products, -&gt; { joins{product_categories.product}.where{products.status.eq &quot;published&quot;}.uniq }</p>
  <p>It is giving the error:
  The method .joins() must contain arguments</p>
  <p>I had other joins statements that I had to fix (numerous). It was due to syntax for a very BASIC example from joins{arguments} to joins(arguments). I assume that is the same case here.  In this case there are many more elements and that lambda expression thrown into the mix which is making it much harder (for me at least) to get it corrected.  I have tried every version of changing that line around I can think of and probably many that do not make sense.  I have one version where it will get past the line but then when that &quot;with_published_products&quot; is called later in the view it errors out with a bad PG statement and when I traced it back it was due to the very same query.   Here is the view involved:</p>
  <pre><code>- if current_user
    .pull-left{style: &quot;position:absolute; top: 10px; left: 20px;&quot;}
      = link_to products_path do
        %button.btn{style: &quot;margin-top: 0px;  &quot;}
          %i.icon-arrow-left.icon-large
          %b back to products
  .row-fluid
    .span12
      %h1.bigred DPF Product Catalog
      %hr
  .row-fluid
    .span12
      - unless @categories.empty?
        .tabbable.tabbable-left
          %ul.nav.nav-tabs{style: &quot;text-align:right;&quot;}
            %li.active
              %a{&quot;data-toggle&quot; =&gt; &quot;tab&quot;, :href =&gt; &quot;#tab-#{@categories.first.id}&quot;} #{@categories.first.name}
            - @categories.each do |category|
              -unless category == @categories.first
                %li
                  %a{&quot;data-toggle&quot; =&gt; &quot;tab&quot;, :href =&gt; &quot;#tab-#{category.id}&quot;} #{category.name}
          .tab-content
            - @categories.each_with_index do |category, i|
              .tab-pane.fade{id: &quot;tab-#{category.id}&quot;, class: &quot;#{ 'in active' if i.zero? }&quot;}
                %h1.bigred.professional{style: &quot;text-align:left;&quot;} #{category.name}
                %hr
                  - @params_name.blank? ? @products = category.products.published.includes(:pictures).order(&quot;name asc&quot;) : @products = category.products.searched(@params_name).published.includes(:pictures).order(&quot;name asc&quot;)
                  = render partial: 'product', collection: @products, cache: true
      - else
        %h2
          There were no products matching
          %b #{@params_name.gsub(/%/, '')}
  </code></pre>
  <p>Here is the Controller:</p>
  <pre><code>class StaticPagesController &lt; ApplicationController
    
    #skip_before_filter :authenticate_user!, :only =&gt; [:catalog, :roi]
    skip_before_action  :authenticate_user!, :only =&gt; [:catalog, :roi]
    
    #skip_authorization_check
    before_action
  
    def home
    end
  
    def help
    end
  
    def catalog
      if params[:name].present?
        @params_name = &quot;%#{params[:name]}%&quot;
        @categories = Category.with_published_products.with_matched_search_terms(@params_name)
      else
        @categories = Category.with_published_products
      end
  
  
      render layout: &quot;catalog&quot;
    end
  
    def roi
  
      render layout: &quot;roi&quot;
    end
  
  
  end
  </code></pre>
  <p>Best I can tell the original author is trying to display product_catagoires that have the status of &quot;published&quot;.  I might be over simplfying the statement but I beleive that is what I understand it to be doing.  I know from other joins I had to fix I had to eliminate the .eq and put =&gt; in its place which I tried many versions of and it always complained about the syntax.  As an example of what I mean this was another section I fixed:</p>
  <p>FROM:</p>
  <ul>
  <li>cds_item = item.variants.joins{vendor}.where{ vendor.code.eq 'cds' }.first</li>
  </ul>
  <p>TO:</p>
  <ul>
  <li>cds_item = item.variants.joins(:vendor).where( :vendor_id =&gt; 'cds' ).first</li>
  </ul>
  <p>I tried to change the line I am having the problem with to a similar format and every combination I could think of I just can't seem to speak to Rails the way it wants.</p>
  <p>If there are any other files I need to attach please let me know.
  I appreciate any input anyone has to offer.<br />
  I am willing to make the scopes less complicated and more verbose if it solves the problem I just am too new to figure this last piece out.</p>
  <p>Thank You,
  Scott</p>
  <p>Thank You @engineersmnky,
  I am now getting the following error:
  Cannot have a has_many :through association 'Category#products' which goes through 'Category#product_categories' before the through association is defined.</p>
  <p>It is referencing this line in the view:</p>
  <pre><code>- @params_name.blank? ? @products = category.products.published.includes(:pictures).order(&quot;name asc&quot;) : @products = category.products.searched(@params_name).published.includes(:pictures).order(&quot;name asc&quot;) 
  </code></pre>
  <p>Sorry if this is not the right way to add more information, I couldn't post the line dealing with the code in a comment.</p>