刚开始玩 Ruby(没有 IT 背景),直到现在进展顺利。但是自从两天以来,我被困住了,不明白出了什么问题……非常感谢您帮助我解决了这个问题!情况如下所述:
我创建了一个包含以下列的currencymastercurrmasdesc:string
表: , currmasiso:string
。我创建了一个包含以下列的货币汇率currratemasteridd:integer
表: , currratemasteridc:integer
, currraterate:decimal
, currratedate:date
。其中,该列currratemasteridd
反映了主要货币,而currratemasteridc
反映了转换后的货币以生成组合的货币对。
models/currencymaster.rb 看起来像这样:
class Currencymaster < ActiveRecord::Base
has_many :CurrencyRateDom, :class_name => "Currencyrate", :foreign_key => "CurrRateMasterIDD"
has_many :CurrencyRateConv, :class_name => "Currencrate", :foreign_key => "CurrRateMasterIDC"
end
models/currencyrate.rb 看起来像这样:
class Currencyrate < ActiveRecord::Base
belongs_to :CurrencyDominant, :class_name => 'Currencymaster' , :foreign_key => "CurrRateMasterIDD", :validate => true
belongs_to :CurrencyConverted, :class_name => 'Currencymaster' , :foreign_key => "CurrRateMasterIDC", :validate => true
end
controllers/currencyrates_controller.rb 看起来像这样:
class CurrencyratesController < ApplicationController
# GET /currencyrates
# GET /currencyrates.json
def index
@currencyrates = Currencyrate.all
respond_to do |format|
format.html # index.html.erb
format.json { render json: @currencyrates }
end
end
# GET /currencyrates/1
# GET /currencyrates/1.json
def show
@currencyrate = Currencyrate.find(params[:id])
respond_to do |format|
format.html # show.html.erb
format.json { render json: @currencyrate }
end
end
end
现在是我的问题,我无法在 view/currencyrates/index.html.erb 中显示相关的currencymaster.currmasiso
而不是存储在表 currencyrate中的currratemasteridd
& 。currratemasteridc
我希望这个问题中的所有信息都可用,否则请在需要其他信息时告诉我。再次感谢!