Note that there are some explanatory texts on larger screens.

plurals
  1. POUsing association params in collections
    primarykey
    data
    text
    <p>I want to narrow down a collection using params accessible through association</p> <pre><code>class PostsController &lt; ApplicationController load_and_authorize_resource def index if params[:event_id] then @event = Event.find(params[:event_id]) if params[:category_id] then @category = Category.find(params[:category_id]) @posts = Post.where(:event_id =&gt; @event.id, :product =&gt; {:category_id =&gt; @category.id }) end end end </code></pre> <p>Gives me the error </p> <pre><code>No attribute named 'category_id' exists for table 'product' </code></pre> <p>But the column 'category_id' does exist in the table 'product'. Searching for this error hasn't shown me anything helpful yet. I've also tried using 'delegate' to make the attribute accessible but that hasn't worked either. I'm stumped.</p> <p>Here is the schema</p> <pre><code> create_table "posts", :force =&gt; true do |t| t.float "quantity" t.datetime "deadline" t.integer "product_id" t.integer "event_id" t.datetime "created_at" t.datetime "updated_at" end create_table "products", :force =&gt; true do |t| t.string "title" t.text "desc" t.text "ingredients" t.float "deposit" t.float "cost" t.string "units" t.float "quantity" t.float "deadline_hours" t.boolean "presell_option" t.integer "user_id" t.integer "category_id" t.integer "club_id" t.datetime "created_at" t.datetime "updated_at" end </code></pre> <p>Edit:</p> <p>When I correct ':product' to ':products' I get this related error</p> <pre><code>SQLite3::SQLException: no such column: products.category_id: SELECT "posts".* FROM "posts" WHERE (("products"."category_id" = 2 AND "posts"."event_id" = 10)) </code></pre> <p>This puzzles me further, the schema says I do have the category_id in the products table</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload