Skip to content
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

Open
wants to merge 7 commits into
base: master
Choose a base branch
from

Conversation

codeblahblah
Copy link

@jwo Assignment is mostly complete apart from the "What would you like to learn more about?" feedback scenario.

@codeblahblah
Copy link
Author

@jwo Show.by_day(input) is a class method call. It works. Is this the right approach?

@codeblahblah
Copy link
Author

@jwo Show.by_day(input) is a class method. It works. Is this the correct approach?

@jwo
Copy link
Member

jwo commented Feb 17, 2014

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 :)

@codeblahblah
Copy link
Author

@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?".
By knowing the Ruby-isms, you can find your way to the solution. Rails itself is based on Ruby's own conventions...

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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

AWESOME

@jwo
Copy link
Member

jwo commented Feb 18, 2014

Great submission.

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?".
By knowing the Ruby-isms, you can find your way to the solution. Rails itself is based on Ruby's own conventions...

That's SO COOL.

@codeblahblah
Copy link
Author

@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. Show.methods.sort doesn't list any 'find' methods, are they hidden in the _find_callback method? Metaprogramming, maybe?

@jwo
Copy link
Member

jwo commented Feb 18, 2014

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")

@codeblahblah
Copy link
Author

@jwo Many thanks. Will go read/watch.
Does using Show#where and the other changes stop SQL injections (i.e. better sanitization)?

@jwo
Copy link
Member

jwo commented Feb 18, 2014

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 find_by_email(“jesse ‘; DROP TABLE USERS”)

Jesse Wolgamott @ Comal Productions, Inc.
Web. Mobile. Design. Training.
@jwo
http://comalproductions.com

On Tuesday, February 18, 2014 at 10:15 AM, drammopo wrote:

@jwo (https://github.com/jwo) Many thanks. Will go read/watch.
Does using Show#where and the other changes stop SQL injections (i.e. better sanitization)?


Reply to this email directly or view it on GitHub (#30 (comment)).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants