5

So I know that Rails helps protect against sql injections when used like this:

Object.find(:first, :conditions=>["name=?",name])

However, I can't seem to find if the autogenerated find_by and find_all_by methods protect agains sql injection.

i.e:

Object.find_by_name(name)

So these two calls have the exact same result. My question is even though the second one is more convenient, should I continue to use the first because it provides protection against sql injection, or does the second do that as well?

1 Answer 1

10

Yes, dynamic attribute-based finders (find_by_* family) do protect your app from sql injections.

Sign up to request clarification or add additional context in comments.

2 Comments

so using where is better than using find?
I withdrew that point as highly subjective. I just like it more. :)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.