I am developing an app in Rails 3.2 that uses the to_params to change the URL/route to a custom one.
The to_params in the model is something like this:
def to_params
keyword
end
Then, in the controllers, I look up the object using:
def show
@object = Object.find_by_keyword(params[:id])
end
I also have a before_save in the model that ensures all keyword entries are lowercase, so the URLs come out like http://mydomain.com/object/keyword.
My question is… Some users might be tempted to capitalize a keyword or something when putting it in the URL themselves. How can I convert that URL into lowercase before trying to find the object in the controller? I’ve tried @object = Object.find_by_keyword(params[:id].lowercase), but it didn’t seem to work.
Any help would be greatly appreciated!
@object = Object.find_by_keyword(params[:id].downcase)Should work