Watchman assignment submission#30
Conversation
|
@jwo |
|
@jwo |
|
Yes, the class method is the correct approach. Great stuff, and I was greatly surprised at the use of lorem ipsum for your own beers :) |
|
@jwo Awesome! Had another Ah-ha moment. I no longer see Sinatra code. Or Rails code. It's all Ruby!!! The question I ask is: "What would Ruby do?". Or rather, "How would it look in Ruby?". P.S: I should create a craft beer named Lorem Ipsum which would be targeted specifically to Web Devs who refuse to use Ruby/Rails. |
|
Great submission.
That's SO COOL. |
|
@jwo Thanks a lot. After I wrote that comment, I came to the realisation that I can change my custom Show#by_day to Show#find_all_by_day_of_week which ActiveRecord should make available to me. More convention! I literally 'guessed' this. |
|
Yes, the “find_by” is metaprogramming, using method_missing. If you call a method that doesn’t exist, it will see if the method you sent starts with “find_by” — if it does, then it does it’s magic Note that the “find_by_email” is deprecated in Rails 4. Instead, it has a “find_by” method. So, instead of User.find_by_email "example@example.com"You’d User.find_by email: "example@example.com"———————— Secondly, to query for many things, you’ll want to use “where” Instead of Show.find_all_by_day_of_week "Tuesday"You should Show.where(day_of_week: "Tuesday") |
|
More info on the ActiveRecord 3.0 query interface:
And on the 4.0 changes: |
|
@jwo Many thanks. Will go read/watch. |
|
As long as you use the AR interface, you will be ok. That is, don’t hand craft SQL… But, find_by_email(“jesse”) is safe from attacked like Jesse Wolgamott @ Comal Productions, Inc. On Tuesday, February 18, 2014 at 10:15 AM, drammopo wrote:
|
@jwo Assignment is mostly complete apart from the "What would you like to learn more about?" feedback scenario.