Ruby (IT 배경 없음)를 시작하고 이전 질문/답변 (link)을 기반으로 프로젝트를 다시 시작했습니다. 이제 다음과 같은 상황을 가지고 : 관련 테이블에서 설명 필드를 표시하는 방법 (2)
은 ID 열이 루비에 의해 생성된다 다음과 같은 열이id:integer
,
description:string
및
isocode:string
와
currencymaster 테이블을 만들었습니다. ID 열에는 루비 의해 생성된다
는 다음 열
id:integer
,
dominant:integer
및
converted:integer
rate:decimal
과 함께
currencyrates 표를 만들었다.
help on this site을 기반으로 다음 모델을 만들었습니다. 모델/currencymaster.rb은 다음과 같습니다
class Currencymaster < ActiveRecord::Base
has_many :currency_rates_dominant, :validate => true, :class_name => 'Currencyrate'
has_many :currency_rates_converted, :validate => true, :class_name => 'Currencyrate'
end
모델을/currencyrate.rb은 다음과 같습니다 : 나는 두 컨트롤러에 아직 아무것도 변경하지 않은
class Currencyrate < ActiveRecord::Base
belongs_to :currency_master_doms, :class_name => 'Currencymaster'
belongs_to :currency_master_convs, :class_name => 'Currencymaster'
end
.
\ currencyrates \ index.html.erb은 Ruby를 통해 자동으로 생성되며 레코드의 값을 정수로 표시합니다. 목표는 Currencymaster
테이블에서 currencymaster.iso
값을 표시하는 것입니다. currencyrate.dominant
및 currencyrate.converted
감사합니다.
@ Dougui : 감사합니다. 다시 시도해보고 코드를 게시하여 나중에 확인하십시오 (제발). 클래스 이름은'generate scaffold' 문에서 루비에 의해 생성됩니다. 나중에 변경할 수 있습니까? – jmk
가능합니다. 코드를 다시 만들 수도 있고, 비계를 생성 할 때 'rails generate scaffold CurrencyRate ...'와 같이 대문자를 추가 할 수 있습니다. 가이드 : http://guides.rubyonrails.org/command_line.html#rails-generate를 참조하십시오. – Dougui
이제'currencyrate' 테이블을'id : integer','dominant_id : integer','converted_id : integer' 및'rate : decimal' 컬럼으로 변경했습니다. – jmk