title: PG::UndefinedTable: ERROR: missing FROM-clause — Searching with two models Rails
body: <p>I have a searchbar on my landing page where I can search for books from users from different universities. It doesn't seem to accept the .joins when it gets redirected to the Book Index Page. Book belongs to user and user has many books.</p>
  
  <p>I always get:</p>
  
  <p>PG::UndefinedTable: ERROR:  missing FROM-clause entry for table "user"</p>
  
  <p>BooksController.rb</p>
  
  <pre><code>def index
    if params[:book][:title].present? &amp;&amp; params[:users][:university].present?
    @books = Book.where({title: params[:book][:title]})
    .joins(:user).where(user: {university: params[:users][:university]}).uniq
    end
  end
  </code></pre>
  
  <p>PagesController.rb</p>
  
  <pre><code>def home
    @books = Book.new
  end
  </code></pre>
  
  <p>And this is my search in simple_form:</p>
  
  <pre><code>&lt;%= simple_form_for [@books], url: books_path, method: :get do |f| %&gt;
    &lt;ul class="list-inline"&gt;
      &lt;li&gt;&lt;%= f.input :title, placeholder: "Title", label: false %&gt;&lt;/li&gt;
      &lt;%= simple_fields_for :users do |r| %&gt;
        &lt;li&gt;&lt;%= r.input :university, placeholder: "University", label: false %&gt;&lt;/li&gt;
      &lt;% end %&gt;
    &lt;/ul&gt;
      &lt;%= f.button :submit, 'search', class: "btn"  %&gt;
  &lt;% end %&gt;
  </code></pre>
  
  <p>routes.rb</p>
  
  <pre><code>resources :books do
    resources :users
  end
  </code></pre>
  
  <p>Full error is:</p>
  
  <blockquote>
    
    
    <p>LINE 1: ... "books"."user_id" WHERE "books"."title" = $1 AND "user"."un...
                                                                 ^
    : SELECT DISTINCT "books".* FROM "books" INNER JOIN "users" ON "users"."id" = "books"."user_id" WHERE "books"."title" = $1 AND "user"."university" = $2></p>
  </blockquote>