jason Mardell

Joined

120 Experience
0 Lessons Completed
0 Questions Solved

Activity

Posted in find_by not returning array but class insance

What am I missing please?

class Choice < ApplicationRecord
belongs_to :choiceable, polymorphic: true
belongs_to :room_item, optional: false
end

create_table "choices", force: :cascade do |t|
t.string "choiceable_type"
t.integer "choiceable_id"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.integer "room_item_id"
t.index ["choiceable_type", "choiceable_id"], name: "index_choices_on_choiceable_type_and_choiceable_id", using: :btree
t.index ["room_item_id"], name: "index_choices_on_room_item_id", using: :btree
end

2 records in the database

[#<Choice:0x00007fd3125859e8 id: 32, choiceable_type: "Appliance", choiceable_id: 1, created_at: Tue, 09 Apr 2019 08:42:38 UTC +00:00, updated_at: Tue, 09 Apr 2019 08:42:38 UTC +00:00, room_item_id: 25>,

#]

I can see in the server

Choice Load (0.8ms) SELECT "choices".* FROM "choices" WHERE "choices"."choiceable_id" IN (1, 6) LIMIT $1 [["LIMIT", 1]]

But when I run a query to get them - I don't get a record set as I expect - I get a SINGLE Choice object???????? WTF is going on?

removed = Choice.find_by(choiceable_id: choiceIds)

puts removed.each { | c | c.marked_for_destruction }

**undefined method `each' for #<Choice:0x00007f7f86e09ea0>**

Thanks Chris - looks like the solution is to add

config.serve_static_files = true

to production.rb

I just get a 404 when I link to /javascripts/lib/add_all_plots.js?

I don't have easy access to the production javascript console - what should I be looking for on there please?

I have added some javascript files to pubic/javascripts/lib and I have referenced them thus

... type="text/javascript" src="/javascripts/lib/add_all_plots.js" ...

They can be loaded in dev no problem. In production they are not available at that url and don't load.

I must be missing something somewhere? A secret handshake maybe? A special spell?

Any help much appreciated