Article View: pl.comp.lang.ruby
Article #424Re: losowy wybór obiektów
From: Bragi Ragnarson
Date: Fri, 09 Feb 2007 09:32
Date: Fri, 09 Feb 2007 09:32
18 lines
1692 bytes
1692 bytes
On Jan 25, 1:01 pm, "punkracy" <punkr...@gmail.com> wrote:
> Mam model Section, w którym trzymam informacje o działach (np.
> Historia, Matematyka, Biologia). Mam też model Question dla pytań
> odpowiednich dla kategorii.
class Section
has_many :questions do
def random(size=4)
find(:all, :limit => size, :order => 'RANDOM()')
end
end
end
@questions = Section.find(:first).questions.random # => Zwraca 4
losowe elementy
Pozdrawiam,
Łukasz
Technical Details
Message-ID:
<1171013527.951473.5950@v33g2000cwv.googlegroups.com>Path:
mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.glorb.com!postnews.google.com!v33g2000cwv.googlegroups.com!not-for-mailReferences:
<1169726490.206776.285870@v45g2000cwv.googlegroups.com>Show Full Headers
Complete Article Headers
Path: mbox-mo1.pugleaf.net!news-archive.icm.edu.pl!news.gazeta.pl!newsfeed.pionier.net.pl!news.glorb.com!postnews.google.com!v33g2000cwv.googlegroups.com!not-for-mail From: "Bragi Ragnarson" <bragi.ragnarson@gmail.com> Newsgroups: pl.comp.lang.ruby Subject: Re: losowy wybór obiektów Date: 9 Feb 2007 01:32:08 -0800 Organization: http://groups.google.com Lines: 19 Message-ID: <1171013527.951473.5950@v33g2000cwv.googlegroups.com> References: <1169726490.206776.285870@v45g2000cwv.googlegroups.com> NNTP-Posting-Host: 195.26.77.1 Mime-Version: 1.0 X-Trace: posting.google.com 1171013535 778 127.0.0.1 (9 Feb 2007 09:32:15 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Fri, 9 Feb 2007 09:32:15 +0000 (UTC) In-Reply-To: <1169726490.206776.285870@v45g2000cwv.googlegroups.com> User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.8.1.1) Gecko/20061201 Firefox/2.0.0.1 (Ubuntu-feisty),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: v33g2000cwv.googlegroups.com; posting-host=195.26.77.1; posting-account=HWkcRAwAAACAHV9lq_vlsb8qSr_RvlpC Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit