i have this in my view, http://pastie.caboo.se/175030 but it doesnt seem to work. im not sure what im doing wrong.. it think i have the wrong syntax. i get "no block given" error on line 5 And what would be the better way to do this? i tried making a method "find_by(field, item)" but it didnt work out.. -- View this message in context: http://www.nabble.com/were-to-put-a-method-tp16480986p16480986.html Sent from the RubyOnRails Users mailing list archive at Nabble.com. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Try this: (Assuming you have a Model defined as: Prop
and that model has an attribute called "category":
<% Prop.find_all_by_category("car").each do |prop| %>
<li><a class="list_item" href=""<%=h prop.year
%> <%=h prop.title
%></a></li>
<% end %>
-Danimal
On Apr 3, 10:09 pm, h4lfl1ng
<h4lfl...-BoNl9JPmOHUAvxtiuMwx3w@public.gmane.org>
wrote:> i have this in my view,http://pastie.caboo.se/175030
> but it doesnt seem to work.
>
> im not sure what im doing wrong.. it think i have the wrong syntax. i get
> "no block given" error on line 5
>
> And what would be the better way to do this? i tried making a method
> "find_by(field, item)" but it didnt work out..
> --
> View this message in
context:http://www.nabble.com/were-to-put-a-method-tp16480986p16480986.html
> Sent from the RubyOnRails Users mailing list archive at Nabble.com.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Well i tried what you said, and it worked.
one thing though. I have multiple items in my category column in the
db, seperated by spaces.. and this is what i tried, with no luck if
there are more than one item.
def find_all_by_category(item)
self.find(:all, :params => {:category => /#{item}/})
end
On Apr 4, 12:20 am, Danimal
<fightonfightw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Try this: (Assuming you have a Model defined as: Prop
> and that model has an attribute called "category":
>
> <% Prop.find_all_by_category("car").each do |prop| %>
> <li><a class="list_item" href=""<%=h
prop.year %> <%=h prop.title
> %></a></li>
> <% end %>
>
> -Danimal
>
> On Apr 3, 10:09 pm, h4lfl1ng
<h4lfl...-BoNl9JPmOHUAvxtiuMwx3w@public.gmane.org> wrote:
>
> > i have this in my view,http://pastie.caboo.se/175030
> > but it doesnt seem to work.
>
> > im not sure what im doing wrong.. it think i have the wrong syntax. i
get
> > "no block given" error on line 5
>
> > And what would be the better way to do this? i tried making a method
> > "find_by(field, item)" but it didnt work out..
> > --
> > View this message in
context:http://www.nabble.com/were-to-put-a-method-tp16480986p16480986.html
> > Sent from the RubyOnRails Users mailing list archive at Nabble.com.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Just incase anyone was wondering, this is what i came up with after
more reading of the api and spending some time on freenode, hope it
helps you.
def self.find_all_by_category(item)
self.find( :all, :conditions => ["category like ?",
"%#{item}%"] )
end
On Apr 4, 12:57 am, Ilya
<h4lfl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Well i tried what you said, and it worked.
> one thing though. I have multiple items in my category column in the
> db, seperated by spaces.. and this is what i tried, with no luck if
> there are more than one item.
>
> def find_all_by_category(item)
> self.find(:all, :params => {:category => /#{item}/})
> end
>
> On Apr 4, 12:20 am, Danimal
<fightonfightw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > Try this: (Assuming you have a Model defined as: Prop
> > and that model has an attribute called "category":
>
> > <% Prop.find_all_by_category("car").each do |prop| %>
> > <li><a class="list_item" href=""<%=h
prop.year %> <%=h prop.title
> > %></a></li>
> > <% end %>
>
> > -Danimal
>
> > On Apr 3, 10:09 pm, h4lfl1ng
<h4lfl...-BoNl9JPmOHUAvxtiuMwx3w@public.gmane.org> wrote:
>
> > > i have this in my view,http://pastie.caboo.se/175030
> > > but it doesnt seem to work.
>
> > > im not sure what im doing wrong.. it think i have the wrong
syntax. i get
> > > "no block given" error on line 5
>
> > > And what would be the better way to do this? i tried making a
method
> > > "find_by(field, item)" but it didnt work out..
> > > --
> > > View this message in
context:http://www.nabble.com/were-to-put-a-method-tp16480986p16480986.html
> > > Sent from the RubyOnRails Users mailing list archive at
Nabble.com.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---
Ilya,
That looks good! Glad you got it working. Basically, it''s a way to do
matches on substrings of category. I.e. if I have a category of "Car"
I could do: Prop.find_all_by_category("ar") and it would match
"Car"
and anything else like that.
The one thing I''d caution you on: this may end up being confusing in
the future. "find_all_by_X" (where X is some attribute on that model)
is already part of AR associations. So you are redefining an existing
method to work differently, which may confuse you or mess you up
later. My recommendation is to call it something differently, maybe
like: find_by_category_substring(item).
Just a suggestion though. :-)
-Danimal
On Apr 8, 8:55 pm, Ilya <h4lfl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> Just incase anyone was wondering, this is what i came up with after
> more reading of the api and spending some time on freenode, hope it
> helps you.
> def self.find_all_by_category(item)
> self.find( :all, :conditions => ["category like
?", "%#{item}%"] )
> end
>
> On Apr 4, 12:57 am, Ilya
<h4lfl...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > Well i tried what you said, and it worked.
> > one thing though. I have multiple items in my category column in the
> > db, seperated by spaces.. and this is what i tried, with no luck if
> > there are more than one item.
>
> > def find_all_by_category(item)
> > self.find(:all, :params => {:category =>
/#{item}/})
> > end
>
> > On Apr 4, 12:20 am, Danimal
<fightonfightw...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
> > > Try this: (Assuming you have a Model defined as: Prop
> > > and that model has an attribute called "category":
>
> > > <% Prop.find_all_by_category("car").each do |prop|
%>
> > > <li><a class="list_item"
href=""<%=h prop.year %> <%=h prop.title
> > > %></a></li>
> > > <% end %>
>
> > > -Danimal
>
> > > On Apr 3, 10:09 pm, h4lfl1ng
<h4lfl...-BoNl9JPmOHUAvxtiuMwx3w@public.gmane.org> wrote:
>
> > > > i have this in my view,http://pastie.caboo.se/175030
> > > > but it doesnt seem to work.
>
> > > > im not sure what im doing wrong.. it think i have the wrong
syntax. i get
> > > > "no block given" error on line 5
>
> > > > And what would be the better way to do this? i tried making
a method
> > > > "find_by(field, item)" but it didnt work out..
> > > > --
> > > > View this message in
context:http://www.nabble.com/were-to-put-a-method-tp16480986p16480986.html
> > > > Sent from the RubyOnRails Users mailing list archive at
Nabble.com.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---