我在Rails開發初學者,我目前在市場上的改進工作已經實現了,我被卡住。內容複製到另一個表的屬性在軌
我想修改代碼,以便它在其中被命名爲「列表」另一個表的另一個屬性名爲「custom_field_values」的表的屬性的複製內容。
我在custom_field_value模型寫了這個代碼:
before_validation :set_date_value
def set_date_value
@current_listing = Listing.where(id: listing_id).select(:valid_until)
@current_listing= date_value
end
出現了一些問題,因爲表值接收空,而不是內容本身。 我也試着使用listing_controller來加入這兩個表並分配值但沒有任何反應,我仍然得到一個空值。
這裏的方式是兩個表模式:
表名:custom_field_values
id :integer not null, primary key
custom_field_id :integer
listing_id :integer
text_value :text(65535)
numeric_value :float(24)
date_value :datetime
created_at :datetime not null
updated_at :datetime not null
type :string(255)
表名:上市
id :integer not null, primary key
uuid :binary(16) not null
community_id :integer not null
author_id :string(255)
category_old :string(255)
title :string(255)
times_viewed :integer default(0)
language :string(255)
created_at :datetime
updates_email_at :datetime
updated_at :datetime
last_modified :datetime
sort_date :datetime
listing_type_old :string(255)
description :text(65535)
origin :string(255)
destination :string(255)
valid_until :datetime
delta :boolean default(TRUE), not null
open :boolean default(TRUE)
share_type_old :string(255)
privacy :string(255) default("private")
comments_count :integer default(0)
subcategory_old :string(255)
old_category_id :integer
category_id :integer
share_type_id :integer
listing_shape_id :integer
transaction_process_id :integer
shape_name_tr_key :string(255)
action_button_tr_key :string(255)
price_cents :integer
currency :string(255)
quantity :string(255)
unit_type :string(32)
quantity_selector :string(32)
unit_tr_key :string(64)
unit_selector_tr_key :string(64)
deleted :boolean default(FALSE)
require_shipping_address :boolean default(FALSE)
pickup_enabled :boolean default(FALSE)
shipping_price_cents :integer
shipping_price_additional_cents :integer
availability :string(32) default("none")
我明白你的問題。但是,您能否公開更多模型代碼,以便我可以給您最好的答案? 現在,你可以寫 '@current_listing = Listing.where(ID:listing_id)。選擇(:valid_until)' '@current_listing.date_value = date_value' '@ current_listing.save' –