0

Just started playing with Ruby (no IT background) and until now went it quite well. But since two days I'm stuck and don't understand what's going wrong... so many thanks already for helping me out with this problem!! The situation is as described below:

I created a currencymaster table with the following columns: currmasdesc:string, currmasiso:string. I created a currencyrate table with the following columns: currratemasteridd:integer, currratemasteridc:integer, currraterate:decimal, currratedate:date. Whereby the column currratemasteridd reflects the Dominant Currency and the currratemasteridc reflects the Converted Currency to generate combined a currency-pair.

The models/currencymaster.rb looks like this:

class Currencymaster < ActiveRecord::Base
  has_many :CurrencyRateDom, :class_name => "Currencyrate", :foreign_key => "CurrRateMasterIDD" 
  has_many :CurrencyRateConv, :class_name => "Currencrate", :foreign_key => "CurrRateMasterIDC"
end

The models/currencyrate.rb looks like this:

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

The controllers/currencyrates_controller.rb looks like this:

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

Now is my problem that I can't show, in the view/currencyrates/index.html.erb , the related currencymaster.currmasiso instead of the currratemasteridd & currratemasteridc stored in the table currencyrate.

I hope all information is avaibale in this question, else please let me know when other information is needed. Thanks again!

Zignd
  • 6,896
  • 12
  • 40
  • 62
jmk
  • 41
  • 5

1 Answers1

0

Why you don't follow conventions?

You should create a CurrencyMaster class, don't repeat "currmas" or "currrate" in your column's name. Don't override foreign keys... You code should be like this :

class CurrencyMaster < ActiveRecord::Base
  has_many :currency_rate_doms
  has_many :currency_rate_convs
end

It's the same in your other classes. Rails use the "convention over configuration principe. It would be better after that.

Welcome to wonderful ruby/rails world.

Dougui
  • 7,142
  • 7
  • 52
  • 87
  • Thanks @Dougui for your quick reply. The reason I didn't follow conventions (as I see now) is that I didn't understood them well I think...Probably I could better restart the project... – jmk Jul 24 '12 at 13:22
  • The is a lot of good tutorial on the Internet. Watch this : http://www.codeschool.com/courses/rails-for-zombies. (Could you up and approv my answer please?) – Dougui Jul 24 '12 at 13:28
  • Ok I have restarted the project with suggested model conventions and database columns but still wondering how I can show the ISO codes in the view of currencyrates. What have I to do, in a ruby on rails method, to enable this function? Much appreciated again! – jmk Jul 26 '12 at 08:32