-
-
Save ysr23/1295352 to your computer and use it in GitHub Desktop.
so i parse my tweet: | |
irb(main):033:0> p qry = reply[1] + " " + reply[2] | |
"bbc1 now" | |
=> "bbc1 now" | |
and these are the arguments that i would like to put on the class Guide | |
(eventually i will need to check that these do match the named scopes i have made) | |
but Guide.bbc1.now does return: | |
irb(main):034:0> Guide.bbc1.now | |
=> [#<Guide id: 75493, start: "2011-10-18 12:45:00", stop: "2011-10-18 13:15:00", title: "Doctors", sub_title: "My Sunshine", description: "Rob makes a shocking discovery about an elderly man...", actors: nil, category: "Soap", episode: "12.119/231.", aspect: nil, quality: nil, created_at: "2011-10-13 08:31:02", updated_at: "2011-10-13 08:31:02", channel: "north-west.bbc1.bbc.co.uk">] | |
so i was just wondering about the syntax of adding that to Guide |
Okay, now I get you. Do you know how to write your named scopes for bbc1
and now
?
I'd be tempted to make the API look like this:
Guide.for_channel('bbc1').on_at('now')
I'm not sure that Guide.bbc1
reads very well, and you don't want data from outside of your app (i.e. Twitter) to be able to choose what methods get called on your own objects. Bit of a security hole.
Look at the definition of :cheaper_than
in [1] to see how to take a parameter. I'd take the class method approach rather than the lambda myself.
[1] http://asciicasts.com/episodes/215-advanced-queries-in-rails-3
yes i have the scopes in my model:
scope :started, where('start < ?', Time.now+1.hour)
scope :notover, where('stop > ?', Time.now+1.hour)
scope :now, started.notover
scope :bbc1, where('channel = ?', "north-west.bbc1.bbc.co.uk")
superb graham i will take a read of that right now and see how to do it - cheers for the security tip and apols again for making this so complicated!
sorry fella.
reply, in this case is just a string its what i pull from twitter:
here its just a string i have made
reply = "@twelly.me bbc1 now".split
qry = reply[1] + reply[2]
so i in the finished example i will check that these are valid scopes but now i am assuming they are so i simply want to pass these scopes to Guide - so it will be interpreted as Guide.bbc1.now but i am not sure of the syntax of doing this - is it even possible to pass this string to Guide - its a syntax question i think : how can i get Guide.qry as it were