Joins, paginate and casting an integer to a string


I need some help please.

I have two tables:





An account can only have one accountdescription but a description can
have many accounts.

I have created two models: account & accdesc

for account I have:
has_one :accdesc

and for accdesc:
belongs_to :accounts

Is this correct? It might be causing the other problem I have …

I want to use paginate to create a list of accounts with their type i.e
do a join between the two. I thought rails did this stuff for me but I
can’t get it to work.

@account_pages, @accounts = paginate :accounts, :per_page => 10

How do I get to the accountdescription please?

Also how do I cast an integer into a string? I have some very complex
SQL I need to run out of find_by_sql and the id is held in

I have googled for all the answers but I haven’t found anything.


Hi Jez,

:account belongs_to :decription
:description has_many :accounts

and of course Account table must include a foreign key to the
description table (Default being used is accdesc_id)

integer casting:

you have 3 options:

  1. use interpolated string => “Elad is #{@programmer.age.to_s} years
  2. concat strings => “Elad is " + @programmer.age.to_s + " years old”
  3. when setting a condition in sql query => SuperHero.find(:first,
    :conditions => [“power_count = ?”, @power_count_needed].

any questions, i’m on [email protected]

hope this helps.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs