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 -- Posted via http://www.ruby-forum.com/.
What database are you using? Did you try making a Chart model? On 7/10/06, Mike <mdalsant@gmail.com> wrote:> > 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 > > -- > Posted via http://www.ruby-forum.com/. > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >-------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060710/7e30c75c/attachment.html
Brian Hogan 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 -- Posted via http://www.ruby-forum.com/.
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")
On 7/10/06, yngwie yngwie <mdalsant@gmail.com>
wrote:>
> Brian Hogan 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
>
>
> --
> Posted via http://www.ruby-forum.com/.
> _______________________________________________
> Rails mailing list
> Rails@lists.rubyonrails.org
> http://lists.rubyonrails.org/mailman/listinfo/rails
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060710/2b73e7db/attachment.html