Hi *, I am writing my first app based on the ''depot'' application but with some suttle differences to help me learn. I am a bit sutck with following and would be grateful for any help: I have the following controller: class MainController < ApplicationController def index @objects = Object.certified_items end end This relates to a field called ''certified'' within a table called objects. The certified field contains an ''int'' of either 0 or 1 - these will become Y/N checkboxes. Within my model I have the following: def self.certified_items find(:all, :conditions => "certified < 1", end end What I am trying to do is use certified as a boolean for yes or no. So if something is not certified ''0'' don''t display it - if it is cerified ''Y'' then do display it. Cheers, Luke
Hey luke, Not quite sure what your question is... You may have your greater/less than the wrong way round? Your certified_items returns non certified items at the moment. I assume you know theres a typo with a missing bracket and an extra comma there too. def certified? self.certified==1 end will return true or false which will be cleaner to use in your controller if you need to test their certifiedness after extraction from the db. -h On 4/12/06, Luke Hinds <Luke.Hinds@mformation.com> wrote:> Hi *, > > I am writing my first app based on the ''depot'' application but with some > suttle differences to help me learn. > > I am a bit sutck with following and would be grateful for any help: > > I have the following controller: > > class MainController < ApplicationController > > def index > @objects = Object.certified_items > end > end > > This relates to a field called ''certified'' within a table called > objects. The certified field contains an ''int'' of either 0 or 1 - these > will become Y/N checkboxes. > > Within my model I have the following: > > def self.certified_items > find(:all, > :conditions => "certified < 1", > end > end > > What I am trying to do is use certified as a boolean for yes or no. So > if something is not certified ''0'' don''t display it - if it is cerified > ''Y'' then do display it. > > > Cheers, > Luke > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
You also can''t use a model named Object, Rails won''t allow it. ( I don''t know if that was just supposed to be a generic example ...) And in your model: def self.certified_items find(:all, :conditions => "certified = 1", end But, like Henry, I''m not exactly sure what the question is... Jeff On 4/12/06, Henry Turner <henryturnerlists@googlemail.com> wrote:> Hey luke, > > Not quite sure what your question is... > > You may have your greater/less than the wrong way round? Your > certified_items returns non certified items at the moment. I assume > you know theres a typo with a missing bracket and an extra comma there > too. > > def certified? > self.certified==1 > end > > will return true or false which will be cleaner to use in your > controller if you need to test their certifiedness after extraction > from the db. > > -h > > On 4/12/06, Luke Hinds <Luke.Hinds@mformation.com> wrote: > > Hi *, > > > > I am writing my first app based on the ''depot'' application but with some > > suttle differences to help me learn. > > > > I am a bit sutck with following and would be grateful for any help: > > > > I have the following controller: > > > > class MainController < ApplicationController > > > > def index > > @objects = Object.certified_items > > end > > end > > > > This relates to a field called ''certified'' within a table called > > objects. The certified field contains an ''int'' of either 0 or 1 - these > > will become Y/N checkboxes. > > > > Within my model I have the following: > > > > def self.certified_items > > find(:all, > > :conditions => "certified < 1", > > end > > end > > > > What I am trying to do is use certified as a boolean for yes or no. So > > if something is not certified ''0'' don''t display it - if it is cerified > > ''Y'' then do display it. > > > > > > Cheers, > > Luke > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >
Hi Jeff & Henry, Thanks for your help :) Here is what worked in the end: class MainController < ApplicationController def index @handsets = Handset.certified_items end class Handset < ActiveRecord::Base def self.certified_items find(:all, :conditions => "certified =1") end end Cheers, Luke -----Original Message----- From: rails-bounces@lists.rubyonrails.org [mailto:rails-bounces@lists.rubyonrails.org] On Behalf Of Jeff Everett Sent: 13 April 2006 00:00 To: rails@lists.rubyonrails.org Subject: Re: [Rails] noob question You also can''t use a model named Object, Rails won''t allow it. ( I don''t know if that was just supposed to be a generic example ...) And in your model: def self.certified_items find(:all, :conditions => "certified = 1", end But, like Henry, I''m not exactly sure what the question is... Jeff On 4/12/06, Henry Turner <henryturnerlists@googlemail.com> wrote:> Hey luke, > > Not quite sure what your question is... > > You may have your greater/less than the wrong way round? Your > certified_items returns non certified items at the moment. I assume > you know theres a typo with a missing bracket and an extra comma there > too. > > def certified? > self.certified==1 > end > > will return true or false which will be cleaner to use in your > controller if you need to test their certifiedness after extraction > from the db. > > -h > > On 4/12/06, Luke Hinds <Luke.Hinds@mformation.com> wrote: > > Hi *, > > > > I am writing my first app based on the ''depot'' application but withsome> > suttle differences to help me learn. > > > > I am a bit sutck with following and would be grateful for any help: > > > > I have the following controller: > > > > class MainController < ApplicationController > > > > def index > > @objects = Object.certified_items > > end > > end > > > > This relates to a field called ''certified'' within a table called > > objects. The certified field contains an ''int'' of either 0 or 1 -these> > will become Y/N checkboxes. > > > > Within my model I have the following: > > > > def self.certified_items > > find(:all, > > :conditions => "certified < 1", > > end > > end > > > > What I am trying to do is use certified as a boolean for yes or no.So> > if something is not certified ''0'' don''t display it - if it iscerified> > ''Y'' then do display it. > > > > > > Cheers, > > Luke > > _______________________________________________ > > Rails mailing list > > Rails@lists.rubyonrails.org > > http://lists.rubyonrails.org/mailman/listinfo/rails > > > _______________________________________________ > Rails mailing list > Rails@lists.rubyonrails.org > http://lists.rubyonrails.org/mailman/listinfo/rails >_______________________________________________ Rails mailing list Rails@lists.rubyonrails.org http://lists.rubyonrails.org/mailman/listinfo/rails