I found the Slimming Controllers guide extremely useful. I only got stuck at one point: on the jumpstartlab version (linked to previously), @cached_article ||= Article.find_or_initialize_by_id(params[:id]) is recommended, while in the GitHub source code, @cached_article ||= Article.find_or_initialize_by(id: params[:id]) is recommended. In my project, only the latter worked, while the former yields a "cannot find method" error.
Thank you very much for this guide, and I hope my feedback is clear and helpful.
Yea, it looks like the former is a convention from Rails 3 and earlier while the latter is used in Rails 4. I'm guessing this tutorial predates Rails 4. Would you be interested in opening a pull request?
Hello,
I found the Slimming Controllers guide extremely useful. I only got stuck at one point: on the jumpstartlab version (linked to previously),
@cached_article ||= Article.find_or_initialize_by_id(params[:id])
is recommended, while in the GitHub source code,@cached_article ||= Article.find_or_initialize_by(id: params[:id])
is recommended. In my project, only the latter worked, while the former yields a "cannot find method" error.Thank you very much for this guide, and I hope my feedback is clear and helpful.
Leo