英文:
Rails 7.0 `Object.group` delivers Object doesn't support #inspect
问题
I've got orders which can be made from different suppliers. I want to group the total amount of money paid by the said supplier.
My SupplierOrder.rb
:
class SupplierOrder < ApplicationRecord
include Order
belongs_to :product
has_many :payments, as: :payable, dependent: :destroy
accepts_nested_attributes_for :payments, allow_destroy: true
end
Now, a simple SupplierOrder.group(:supplier)
in the console delivers me:
SupplierOrder.group(:supplier)
SupplierOrder Load (0.5ms) SELECT "supplier_orders".* FROM "supplier_orders" GROUP BY "supplier_orders"."supplier"
(Object doesn't support #inspect)
=>
If it's helpful, here my schema.rb
:
create_table "supplier_orders", force: :cascade do |t|
t.float "paid"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.float "price"
t.string "supplier"
t.string "order_number"
t.integer "amount"
t.bigint "product_id"
t.index ["product_id"], name: "index_supplier_orders_on_product_id"
end
Here is my order.rb Concern
(models/concerns/order.rb
):
module Order
extend ActiveSupport::Concern
def full_title
self.product.full_title
end
end
Right now I'm getting supplier
-Value from a global variable, defined in helpers/application_helper.rb
:
module ApplicationHelper
SIZES = %w(1:1 1:2 1:3 1:4 1:5 1:6 1:7 1:8)
VERSIONS = %w(regular deluxe exclusive)
COLORS = %w(black blue white)
SUPPLIERS = %w(A B C D)
end
I don't override any initializers like in linked topics or do anything extraordinary. All (at least for now) other methods do work in the console, but just this one is not.
英文:
I've got orders which can be made from different suppliers. I want to group the total amount of money paid by the said supplier.
My SupplierOrder.rb
:
class SupplierOrder < ApplicationRecord
include Order
belongs_to :product
has_many :payments, as: :payable, dependent: :destroy
accepts_nested_attributes_for :payments, allow_destroy: true
end
Now, a simple SupplierOrder.group(:supplier)
in the console delivers me:
SupplierOrder.group(:supplier)
SupplierOrder Load (0.5ms) SELECT "supplier_orders".* FROM "supplier_orders" GROUP BY "supplier_orders"."supplier"
(Object doesn't support #inspect)
=>
If it's helpful, here my schema.rb
:
create_table "supplier_orders", force: :cascade do |t|
t.float "paid"
t.datetime "created_at", null: false
t.datetime "updated_at", null: false
t.float "price"
t.string "supplier"
t.string "order_number"
t.integer "amount"
t.bigint "product_id"
t.index ["product_id"], name: "index_supplier_orders_on_product_id"
end
Here is my order.rb Concern
(`models/concerns/order.rb'):
module Order
extend ActiveSupport::Concern
def full_title
self.product.full_title
end
end
Right now I'm getting supplier
-Value from a global variable, defined in helpers/application_helper.rb
:
module ApplicationHelper
SIZES = %w(1:1 1:2 1:3 1:4 1:5 1:6 1:7 1:8)
VERSIONS = %w(regular deluxe exclusive)
COLORS = %w(black blue white)
SUPPLIERS = %w(A B C D)
end
I don't override any initializers like in linked topics or do anything extraordinary. All (at least for now) other methods do work in the console, but just this one is not.
答案1
得分: 1
在Gemfile的开发组中添加 gem 'pry-rails'
,然后运行 bundle install
,再在rails控制台中执行该命令。
英文:
Add gem 'pry-rails'
in your development group in Gemfile and run bundle install
and execute the command again in rails console.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论