[Rails] Re: finding particular record

Brian Hogan
Mon, 10 Jul 2006 17:44:20 -0000

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...