Rails Learnings for Benefit Glorious Me
I’m finally plugging away at at my first wholly-owned Rails application. It be late, so I’ll just briefly note that one can do SQL LIKE statements with MySQL semi-safely with the following snippet:
find( :all,
:conditions => ["description RLIKE ?", '.*' + description + '.*'] )
while gets translated into the following SQL:
SELECT * FROM waypoints WHERE (description RLIKE '.*Illinois.*')
I’ve not yet read the security chapter for AWDwR, so I don’t know whether this is recommended or not
Note to self: Shouldn’t this be on the Rails Wiki?
_
Also, I keep getting caught with ‘You have a nil object when you didn’t expect it! You might have expected an instance of Array’, even when I was checking if an object was Nil or not. Now I’ve learned that checks like this won’t work:
if params[:waypoint][:stop].nil?
@waypoints = []
end
because they were evaluating to something like nil[:stop].nil?, which don’t fly. I now have code that does this, but it’s ugly, so I need to ask around about what the proper way to do this is.
if params.nil? || params[:waypoint].nil?
@waypoints = []
end
Trackbacks
Use the following link to trackback from your own site:
http://typo.pburkholder.com/articles/trackback/910