-
Notifications
You must be signed in to change notification settings - Fork 27
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Watchman assignment submission #30
base: master
Are you sure you want to change the base?
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. |
puts "\n\nWhat would you like to learn more about?" | ||
input = gets.chomp.titlecase | ||
|
||
beer = Beer.find_by_name(input) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
AWESOME
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 "[email protected]" You’d User.find_by email: "[email protected]" ———————— 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.