Finding particular record

Hi,

I’m looking for a particular record from a view called ‘charts’. The
view ‘charts’ joins data from a table ‘record’ and a table ‘owners’.
I’m trying to pull up data from ‘charts’ that lists certain data from
‘record’

ie. I know i need record.id = 5. Is there a way to do a search from
the controller side to find the chart that contains record.id =5?

Thanks in advance, Mike

What database are you using?

Did you try making a Chart model?

Brian H. wrote:

What database are you using?

Did you try making a Chart model?

yes, i made a model. From the particular view, i’m not sure how to tell
the controller the id of the chart that i need pulled up. I do know the
value of a particular field in ‘chart’, i just can’t get the syntax
down.

mike

Assuming you have a Charts table (or view) and you have a column called
“id”

class Chart < ActiveRecord::Base
end

@chart = Chart.find 1

gets you the chart with the id of 1

Now if you don’t have a column called ID… say you have a different
primary
key… no problem.

class Chart < ActiveRecord::Base
set_primary_key “foo”
end

where “foo” is the name of the column you want to use as your key. Did
you
alias records.id as record_id? If you did, then you can do

class Chart < ActiveRecord::Base
set_primary_key “record_id”
end

You can use dynamic finders to get at anything you need

@chart = Chart.find_by_id 5
@chart = Chart.find_all_by_owner (“somethind”)

or just be lazy

@charts = Chart.find_by_sql(“select * from charts where owner_id = 25”)