softwareengineer 99
2006-Jan-26 07:25 UTC
[Rails] Using variables within a string - The function doesn''t pass the value?
Hello everyone,
As a beginner to ROR, I am very confused regarding why the following is
happening.
If my function is defined as
def self.home_categories (portal_id)
find(:all, :conditions => [ "portal_id=?", portal_id ] )
end
the following doesn''t works (the database is queried with a value of
0.
portal_id=1
@categories = Category.home_categories (:portal_id)
but this works
@categories = Category.home_categories (1)
However,
If my function is defined as
def self.home_categories (portal_id)
find(:all, :conditions => "portal_id=#{portal_id}" )
end
then the following works
portal_id=1
@categories = Category.home_categories (portal_id)
and the following also works:
@categories = Category.home_categories (1)
Why is that happening? Any pointers / explanation is appreciated.
Thanks
Frank
P.S. Thank you Ezra for your assistance with my earlier question and
clarifying how I accidentally hijacked the thread. My sincerest apologies to
the list members and the thread owner for the accidental hijack.
---------------------------------
Do you Yahoo!?
With a free 1 GB, there''s more in store with Yahoo! Mail.
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://wrath.rubyonrails.org/pipermail/rails/attachments/20060126/b0f5e695/attachment.html
Eric Goodwin
2006-Jan-26 07:30 UTC
[Rails] Using variables within a string - The function doesn''t pass the value?
Hi,
From what I can see of your code I think there is just a small typo.
You are using a symbol instead of a var.
portal_id=1
@categories = Category.home_categories (:portal_id)
should be:
portal_id=1
@categories = Category.home_categories (portal_id)
That''s all that I can see. Other than that it should work.
Eric
softwareengineer 99 wrote:
> Hello everyone,
>
> As a beginner to ROR, I am very confused regarding why the following
> is happening.
>
> If my function is defined as
>
> def self.home_categories (portal_id)
> find(:all, :conditions => [ "portal_id=?", portal_id ]
)
> end
>
> the following doesn''t works (the database is queried with a value
of 0.
>
> portal_id=1
> @categories = Category.home_categories (:portal_id)
>
> but this works
>
> @categories = Category.home_categories (1)
>
>
> However,
>
> If my function is defined as
>
> def self.home_categories (portal_id)
> find(:all, :conditions => "portal_id=#{portal_id}" )
> end
>
> then the following works
>
> & nbsp; portal_id=1
> @categories = Category.home_categories (portal_id)
>
> and the following also works:
>
> @categories = Category.home_categories (1)
>
>
> Why is that happening? Any pointers / explanation is appreciated.
>
> Thanks
> Frank
>
> P.S. Thank you Ezra for your assistance with my earlier question and
> clarifying how I accidentally hijacked the thread. My sincerest
> apologies to the list members and the thread owner for the accidental
> hijack.
>
> ------------------------------------------------------------------------
> Do you Yahoo!?
> With a free 1 GB, there''s more in store with Yahoo! Mail.
>
<http://us.rd.yahoo.com/mail_us/taglines/mailstorage/*http://mail.yahoo.com/>
>
>
>------------------------------------------------------------------------
>
>_______________________________________________
>Rails mailing list
>Rails@lists.rubyonrails.org
>http://lists.rubyonrails.org/mailman/listinfo/rails
>
>
softwareengineer 99
2006-Jan-26 07:37 UTC
[Rails] Using variables within a string - The function doesn''t pass the value?
Thanks Eric, That totally works. I thought I had read in the "Agile ROR" book to use symbols but obviously I was wrong. Long day for me. Thanks for the rescue again. Frank --------------------------------- Bring words and photos together (easily) with PhotoMail - it''s free and works with Yahoo! Mail. -------------- next part -------------- An HTML attachment was scrubbed... URL: http://wrath.rubyonrails.org/pipermail/rails/attachments/20060126/81c4a271/attachment.html
Mikkel Bruun
2006-Jan-26 11:38 UTC
[Rails] Re: Using variables within a string - The function doesn''t p
softwareengineer 99 wrote:> Hello everyone, > > > portal_id=1 > @categories = Category.home_categories (:portal_id)portal_id is a variable, :portal_id is a symbol...they dont mix... use: portal_id=1 @categories = Category.home_categories (portal_id) Mikkel -- Posted via http://www.ruby-forum.com/.