ruby on davidchua https://dchua.com/tags/ruby/ Recent content in ruby on davidchua Hugo -- gohugo.io en-us Tue, 24 Mar 2015 00:00:00 +0000 Configuring Chef https://dchua.com/posts/2015-03-24-configuring-chef/ Tue, 24 Mar 2015 00:00:00 +0000 https://dchua.com/posts/2015-03-24-configuring-chef/ Preparing Cookbooks Lets prepare a cookbook. Uploading a cookbook $ knife cookbook upload -a Databags Creating a databag $ knife data_bag create 'users' Uploading a databag $ knife data_bag from file users path/to/data_bag/files Bootstraping Create a new node In order to bootstrap a server to get and use chef, ensure that you have ssh access to your server already. You can define which user to login as using the –ssh-user command below. Setting up Chef https://dchua.com/posts/2015-03-24-setting-up-chef/ Tue, 24 Mar 2015 00:00:00 +0000 https://dchua.com/posts/2015-03-24-setting-up-chef/ Prerequisite: Chef 12.1.x Setting up Chef-Server Download Chef on your Chef-Server $ wget https://web-dl.packagecloud.io/chef/stable/packages/ubuntu/trusty/chef-server-core_12.0.5-1_amd64.deb $ sudo dpkg -i chef-server-core_*.deb $ sudo chef-server-ctl reconfigure Install Opscode-Manage Web interface for Chef management (highly recommended) Note: Opscode-Manage will run on port 80 so keep that free. # On Chef-server $ chef-server-ctl install opscode-manage $ opscode-manage-ctl reconfigure $ chef-server-ctl reconfigure Setup your User and Organization Users are an account that will be used to connect to Chef-server. How to Test for File Operations with FakeFS and RSpec https://dchua.com/posts/2014-12-24-how-to-test-for-file-operations-with-fakefs-and-rspec/ Wed, 24 Dec 2014 00:00:00 +0000 https://dchua.com/posts/2014-12-24-how-to-test-for-file-operations-with-fakefs-and-rspec/ Background: Say you have controller method that creates and writes into a file and you’d like to be able to run expectations on the behavior and not so much of the implementation. The normal way would be to do something like: def test_creates_directory FileUtils.expects(:mkdir).with("directory").once Library.add "directory" end because this just doesn’t work. def test_creates_directory Library.add "directory" assert File.directory?("directory") end So one way to solve this is with this gem called FakeFS. How to Move your Rubygems from one Ruby version to another in RVM https://dchua.com/posts/2014-11-04-moving-your-rubygems-from-one-ruby-version-to-another-in-rvm/ Tue, 04 Nov 2014 00:00:00 +0000 https://dchua.com/posts/2014-11-04-moving-your-rubygems-from-one-ruby-version-to-another-in-rvm/ Today’s post is going to be a pretty short one. So you know how sometimes when requirements change and your entire project have to change (either to upgrade or to downgrade) from one Ruby version to another, you don’t want to have to reinstall and setup your gems all over again? Here’s a quick little tip to quickly move your gems from one version to another. Assuming that you’re currently using Ruby 2. How to Generate PDFs with HTML templates in 10 minutes with Rails https://dchua.com/posts/2014-10-30-generate-pdfs-with-html-templates-in-rails/ Thu, 30 Oct 2014 00:00:00 +0000 https://dchua.com/posts/2014-10-30-generate-pdfs-with-html-templates-in-rails/ Generating PDF for your webapplication is not that difficult as you think. There are many ways to do this, and there’s another great gem out there that does this functionality quite well too, called Prawn, but for the purpose of todays' tutorial, I’ll be going through another popular gem called wicked_pdf instead. WickedPDF uses wkhtmltopdf which allows you to generate PDFs directly from HTML without having to adhere to a DSL. Run a webrick server to serve static html content in a folder https://dchua.com/posts/2014-09-19-run-a-webrick-server-to-serve-static-html-content-in-a-folder/ Fri, 19 Sep 2014 00:00:00 +0000 https://dchua.com/posts/2014-09-19-run-a-webrick-server-to-serve-static-html-content-in-a-folder/ Need a quick way to serve html files? Want to quickly share your static website to the rest of the world, this snippet might help: /directory/to/static/html$ ruby -run -e httpd . -p 9000 Reference: Tenderlove’s Twitter Authenticating with Pagekite API using Ruby https://dchua.com/posts/2014-08-31-authenticating-with-pagekite-api-using-ruby/ Sun, 31 Aug 2014 00:00:00 +0000 https://dchua.com/posts/2014-08-31-authenticating-with-pagekite-api-using-ruby/ If you’re using pagekite, you probably have read this document. It tells you how to connect to pagekite’s XMLRPC service to perform actions such as creating a new kite, checking your accounts etc. Their example is in python and if you’re like me, trying to figure out how to get it to work in Ruby, here’s my snippet: # lets do this - test.rb require 'xmlrpc/client' server = XMLRPC::Client.new_from_uri('https://pagekite.net/xmlrpc/') # note that you really need that trailing slash after /xmlrpc. Equivalent of try() for hashes? - Ruby https://dchua.com/posts/2014-08-17-equivalent-of-try-for-hashes-ruby/ Sun, 17 Aug 2014 11:41:36 +0800 https://dchua.com/posts/2014-08-17-equivalent-of-try-for-hashes-ruby/ To do a try() on hashes, its as simple as: # to get data['something_value'] @item = @model.try(:data).try(:[], 'something_value'] 2021 Update From ruby 2.3.0 you can now do the following shorthand @model&.data&.[](:something_value) Reference: Safe navigation equivalent to Rails try for hashes References: Equivalent of .try() for a hash? Ruby Multithreading with Threadwait https://dchua.com/posts/2014-05-22-ruby-multithreading-with-threadwait/ Thu, 22 May 2014 00:00:00 +0000 https://dchua.com/posts/2014-05-22-ruby-multithreading-with-threadwait/ Multithreading is nothing new in Ruby but its only in recent times that I’ve found a use for it. Unlike background processes which runs your task on its own instance independently from the main rails app, Multithreading also runs each threads separately but needs to join back with the main thread in order to continue. An example use: @groups.each do |t| threads << Thread.new do t.process_something end end # Group def process_something # calls external resources and wait for a reply. Format strings dynamically in ruby https://dchua.com/posts/2014-03-16-format-strings-dynamically-in-ruby/ Sun, 16 Mar 2014 00:00:00 +0000 https://dchua.com/posts/2014-03-16-format-strings-dynamically-in-ruby/ #TIL you can format strings dynamically and neatly with: puts "%s is at %s" % [ 'John', 'Singapore' ] => John is at Singapore 2021 Update The above is similar to how we do it in go person := "John" country := "Singapore" fmt.Printf("%s is at %s", person, country) References: Stackoverflow Big Ruby 2014 Video - Throw some keys in it Carrierwave Fog - Need a local file? Use Cache! https://dchua.com/posts/2014-02-27-carrierwave-fog-need-a-local-file-use-cache-/ Thu, 27 Feb 2014 20:40:50 +0800 https://dchua.com/posts/2014-02-27-carrierwave-fog-need-a-local-file-use-cache-/ If you’re like me, using carrierwave + fog to hook up your Model witih Amazon S3, you may encounter this problem where you need to reprocess an image and you can’t do so without downloading the file locally. In my case, I need a to_file() method done on one of my assets but using Carrierwave/Fog(S3) and in order for that to happen the file needs to be a Carrierwave::SanitizedFile. So what can I do? Sum up array contents with a simple method https://dchua.com/posts/2014-02-23-sum-up-array-contents-with-a-simple-method/ Sun, 23 Feb 2014 00:00:00 +0000 https://dchua.com/posts/2014-02-23-sum-up-array-contents-with-a-simple-method/ With just: array.inject(:+) It will take an array and sum it up. >> [0,2,3,1] >> [0,2,3,1].inject(:+) => 6 Exclude individual css from assets pipeline https://dchua.com/posts/2013-12-22-exclude-individual-css-from-assets-pipeline/ Sun, 22 Dec 2013 00:00:00 +0000 https://dchua.com/posts/2013-12-22-exclude-individual-css-from-assets-pipeline/ When in the need to remove certain CSS files from your application.css’s require_tree: # application.css /* *= require_self *= require_tree . */ Use sprocket’s stub directive: # application.css /* *= require_self *= require_tree . *= stub whatevercssyoudontwanttoload[.css] */ Note: Best practice of course is to add individual stylesheets into your application.css rather than a full on require_tree .. But in the event that you require to still use require_tree, the above may help you. The Mystery Behind Ruby Require and Load Paths https://dchua.com/posts/2013-09-12-the-mystery-behind-ruby-require-and-load-paths/ Thu, 12 Sep 2013 00:00:00 +0000 https://dchua.com/posts/2013-09-12-the-mystery-behind-ruby-require-and-load-paths/ Ruby require used to annoy the hell out of me. Because back then I didn’t know how to use it, or what exactly it does. I knew that I need to ‘require’ in order to use custom Classes I’ve created. But what to put in the ‘require …’, has always been trial and error for me. Basically, ‘require’ takes in a param which contains the path to your custom class(es) that is stored in a . Ruby Rescuing Precedence https://dchua.com/posts/2013-08-25-ruby-rescuing-precedence/ Sun, 25 Aug 2013 00:00:00 +0000 https://dchua.com/posts/2013-08-25-ruby-rescuing-precedence/ When doing a rescue_from in your controller, note that: # controller rescue_from Exception, :with => :do_this rescue_from SomeOtherException, :with => :do_that def ... Exceptions always run in precedence, with the later rescue taking in a higher priority. Therefore, if you ever want SomeOtherException to be rescued, it has to be later than the catch-all Exception. Capistrano - Setup log directories and database.yml https://dchua.com/posts/2013-08-17-capistrano-setup-log-directories-and-database-yml/ Sat, 17 Aug 2013 00:00:00 +0000 https://dchua.com/posts/2013-08-17-capistrano-setup-log-directories-and-database-yml/ Updated my deploy.rb gist. Created a new setup_config task that should be run the first time you setup your server. This fixes the missing database.yml file, and setups the missing log directories in your Rails app. Also creates a helper method that checks if a remote_file exists. # config/deploy.rb before 'deploy:db:symlink_db', 'deploy:setup_config' def remote_file_exists?(full_path) 'true' == capture("if [ -e #{full_path} ]; then echo 'true'; fi").strip end namespace :deploy do task :setup_config do run " Rspec Generator Files https://dchua.com/posts/2013-08-10-rspec-generator-files/ Sat, 10 Aug 2013 00:00:00 +0000 https://dchua.com/posts/2013-08-10-rspec-generator-files/ If RSpec for some reason doesn’t generate your spec files when generating models and controllers, add this to your config/application.rb. config.generators do |g| g.test_framework :rspec, :fixtures = true, :view_specs = false, :helper_specs = false, :routing_specs = false, :controller_specs = true, :request_specs = true g.fixture_replacement :factory_girl, :dir = "spec/factories" end SimpleCov for Spork/RSpec (Code Test Coverage) https://dchua.com/posts/2013-08-06-simplecov-for-sporkrspec-code-test-coverage/ Tue, 06 Aug 2013 00:00:00 +0000 https://dchua.com/posts/2013-08-06-simplecov-for-sporkrspec-code-test-coverage/ If you’re into testing, you know about test coverages. Some developers aim to strive 100% coverage, but personally, I’d avoid being dogmatic about test coverage. After all test coverage is doesn’t ensure that your code is well tested. But if you’re into test coverage, or just want a quick and easy way to view your team’s test progress, this gem, simplecov, maybe what you’re looking for. SimpleCov generates a HTML report in coverage/ located in your Rails. Resque your RSpec https://dchua.com/posts/2013-07-31-resque-your-rspec/ Wed, 31 Jul 2013 00:00:00 +0000 https://dchua.com/posts/2013-07-31-resque-your-rspec/ To start testing your Resque: Use the awesome ResqueSpec # Gemfile group :test do ... gem 'resque_spec' ... end In your spec testing, play around with “have_queue_size_of” and “have_queued”. Example, if you have a worker called SoldPropertyMessenger with its perform action taking in a param of an ‘id’ # app/workers/sold_property_messenger.rb class SoldPropertyMessenger @queue = :notification def self.perform(id) # magic end end Your spec/controller test could do something like: Howto: Multiple Redis Database for Different Rails Environment https://dchua.com/posts/2013-07-30-howto-multiple-redis-database-for-environment/ Tue, 30 Jul 2013 00:00:00 +0000 https://dchua.com/posts/2013-07-30-howto-multiple-redis-database-for-environment/ This is a personal note to self. Referenced from a post on Stackoverflow. One problem I had with running Redis on my Rails app was that on the default configuration, Redis can’t tell if you’re on development or production and hence when doing tests, you may overwrite your development data. To solve this, lets setup redis to use the correct database for the correct environment: Add config/redis.yml #config/redis.yml default: host: localhost port: 6379 development: db: 0 # namespace: appname_dev test: db: 1 # namespace: appname_test production: db: 2 host: localhost # namespace: appname_prod Update the config/initializer/redis. Redis::InheritedError during RSpec/Spork Testing https://dchua.com/posts/2013-07-30-redisinheritederror-during-rspecspork-testing/ Tue, 30 Jul 2013 00:00:00 +0000 https://dchua.com/posts/2013-07-30-redisinheritederror-during-rspecspork-testing/ When testing an action that performs a redis-rb command on RSpec, you may run into an error: Redis::InheritedError (Tried to use a connection from a child process without reconnecting ... Solve it by adding the following into your spec_helper. # spec/spec_helper.rb RSpec.configure do |config| # ... config.before :all do $redis.client.reconnect end # ... end Saves me ton of time. Reference: Stackoverflow Whenever - Easy Cronnable Rake Tasks! With Capistrano! https://dchua.com/posts/2013-07-17-whenever-easy-cronnable-rake-tasks-with-capistrano/ Wed, 17 Jul 2013 00:00:00 +0000 https://dchua.com/posts/2013-07-17-whenever-easy-cronnable-rake-tasks-with-capistrano/ We all have this problem before. Attempting to write a crontab that runs a rake task is almost a painful endeavor. Especially if you’re running a ruby version manager like RVM. Luckily, this crontab DSL gem, “Whenever”, created by Javan, helps make things so much easier. To get started, make sure you have whenever in your Gemfile: #Gemfile gem 'whenever' Then, run wheneverize: /home/myapp$ wheneverize . This will create your config/scheduler. Loading 'deploy/assets' in Capistrano, automatically precompiles:assets https://dchua.com/posts/2013-07-14-loading-deployassets-in-capistrano-automatically-precompilesassets/ Sun, 14 Jul 2013 00:00:00 +0000 https://dchua.com/posts/2013-07-14-loading-deployassets-in-capistrano-automatically-precompilesassets/ Something that I’ve just figured out after tinkering for a couple of hours. Hope this will save someone else some trouble. So I’m running my own custom Capistrano script that on fresh deploy setup a symlink of database.yml on the app instance, so that you don’t need to check in your database.yml file. So in my config/deploy.rb, I have something like: after 'deploy:update_code', 'deploy:symlink_db', 'deploy:assets:precompile' . . . . desc " Testing PaypalExpress Gateway on ActiveMerchant https://dchua.com/posts/2013-06-24-testing-paypalexpress-gateway-on-activemerchant/ Mon, 24 Jun 2013 00:00:00 +0000 https://dchua.com/posts/2013-06-24-testing-paypalexpress-gateway-on-activemerchant/ Background: ActiveMerchant’s BogusGateway class which is usually used in a Test environment, does not have setup_purchase/setup_authorization method which is used in Paypal’s Express Checkout. This gives an: undefined method `setup_purchase' for # When testing for controller actions that interact with ActiveMerchant’s Paypal Express Gateway. To fix this, according to Skud, you will need to download and unpack the active_merchant and active_utils gems into your local vendor directory. /webapps/myapp/$ gem unpack /path/to/activemerchant-1. RVM MRI 2.0.0-rc1 installs giving you trouble? https://dchua.com/posts/2013-05-08-rvm-mri-2-0-0-rc1-installs-giving-you-trouble/ Wed, 08 May 2013 00:00:00 +0000 https://dchua.com/posts/2013-05-08-rvm-mri-2-0-0-rc1-installs-giving-you-trouble/ RVM Ruby 2.0.0-rc1 installs giving you problem? Getting this Error? Error running 'make', please read /Users/katz/.rvm/log/ruby-2.0.0-rc1/make.log OSX brew install openssl rvm get head CC=clang rvm install 2.0.0 -C --enable-shared, --with-openssl-dir=/usr/local Ubuntu sudo apt-get install openssl rvm get head rvm install 2.0.0 -C --enable-shared, --with-openssl-dir=/usr/local Source: http://www.blog.bridgeutopiaweb.com/post/install-ruby-2-dot-0-0-with-rvm Custom Exception Handling https://dchua.com/posts/2013-03-10-custom-exception-handling/ Sun, 10 Mar 2013 00:00:00 +0000 https://dchua.com/posts/2013-03-10-custom-exception-handling/ Note to self: For some better practice, handle custom exceptions by: Declaring a custom exception module. # In /lib/exceptions/app_exception.rb module AppException class AnyExceptionName < StandardError end end Do try and keep to the relevant exception subclasses (ie. StandardError v Error). Refer to this. # In /config/application.rb # ensure that autoload path is un-commented to allow rails to load your custom exception library config.autoload_paths += %W(#{config.root}/lib/exceptions) Now, you can raise AppException::AnyExceptionName anytime you want! Pusher + Slanger - Publish away! https://dchua.com/posts/2013-01-29-pusher-slanger-publish-away/ Tue, 29 Jan 2013 00:00:00 +0000 https://dchua.com/posts/2013-01-29-pusher-slanger-publish-away/ Played around with Pusher today. Surprisingly, it was an easy push. If you haven’t heard about Pusher, it is a hosted API that allows you to quickly build publish-subscribe messaging functionality into your web application. Like most hosted APIs, they work on a freemium model and charge only when you use up to 100 concurrent connections at a time. Pusher provides a pusher-gem which lets your Rails controllers send out publish messages. Bypassing mass-assignment protection in rake db:seed https://dchua.com/posts/2012-12-19-bypassing-mass-assignment-protection-in-rake-dbseed/ Wed, 19 Dec 2012 00:00:00 +0000 https://dchua.com/posts/2012-12-19-bypassing-mass-assignment-protection-in-rake-dbseed/ Reference: GilesBowkett So I ran this problem the other day on a project where the db/seed.rb file couldn’t run due to mass-assignment protection. Instead of adding the attribute in attr_accessible on the model side and then removing it after running the seed data, there’s actually another way to do it. Giles suggested adding attr_accessible directly into the seed file itself, such that it will temporarily disable mass-assignment protection for the duration of the rake db:seed. The Splat(*) Operator https://dchua.com/posts/2012-05-18-the-splat-operator/ Fri, 18 May 2012 00:00:00 +0000 https://dchua.com/posts/2012-05-18-the-splat-operator/ Learnt something new today. When trying to split a multi-dimensional array, one could use the *(splat) operator. a = [[1,2],[3,4]] b = [[5,6],[7,8]] In order to include b into a without breaking the array, you could do the following: a = [[1,2],[3,4], *b] # a = [[1,2],[3,4],[5,6],[7,8]] And that’s the magic of *splat. Update: Amazon S3, Paperclip and a Curious Case of Singapore Buckets https://dchua.com/posts/2012-04-25-update-amazon-s3-paperclip-and-a-curious-case-of-singapore-buckets/ Wed, 25 Apr 2012 00:00:00 +0000 https://dchua.com/posts/2012-04-25-update-amazon-s3-paperclip-and-a-curious-case-of-singapore-buckets/ This is an update of my previous blog post, “How to get Paperclip and AWS S3 Singapore and European Buckets Working”. Since the post last year in December, Amazon had released its official AWS SDK for ruby which is now available as the ‘aws-sdk’ rubygem. Paperclip had also made an update in its core to directly support AWS-SDK over marcel’s AWS-S3 gem. This little guide is supposed to help you get quickly started uploading your images into S3 via Paperclip and the new gem. Some tips to deploying Rubber-powered EC2 Rails Apps https://dchua.com/posts/2012-01-07-some-tips-to-deploying-rubber-powered-ec2-rails-apps/ Sat, 07 Jan 2012 00:00:00 +0000 https://dchua.com/posts/2012-01-07-some-tips-to-deploying-rubber-powered-ec2-rails-apps/ I’ve been playing around with Rubber, the EC2 deployment script for Rails lately and I’ve spent a huge amount of time trying to get it to work. Here are some of my notes: To setup: # Put this into Gemfile gem rubber Vulcanize! (Create the deployment scripts according to your specifications) On Rails 3.x, in your Rails application’s root directory davidc@davidc:~/my/awesome/app> vulcanize <option> # with option being any one of the following minimal_nodb, redis, passenger_nginx, complete_passenger_nginx, cruise, postgresql, resque, apache, sphinx, monit, minimal_passenger_nginx, mysql_cluster, complete_passenger_postgresql, cassandra, mongodb, complete_mongrel_mysql, complete_passenger_nginx_postgresql, base, memcached, minimal_mysql, complete_passenger_mysql, complete_passenger_nginx_mysql, munin, mysql_proxy, complete_passenger, mysql, nginx, jetty, passenger, haproxy, mongrel Edit /config/rubber/rubber. Rails 3.2 RC1 released! https://dchua.com/posts/2011-12-20-rails-3-2-rc1-released/ Tue, 20 Dec 2011 00:00:00 +0000 https://dchua.com/posts/2011-12-20-rails-3-2-rc1-released/ Woke up this morning to a tweet by DHH: Rails 3.2 (Release Candidate 1) has been released! And it has pretty exciting features to boot like: Faster dev mode & routing Explain queries Tagged logger ActiveRecord Store I’m in particularly excited about tagged logging. For far too long, developers have to struggle with trying to figure out whose Logger.info belonged to who. Can’t wait to try them out. Rails 3.1x Migration Change https://dchua.com/posts/2011-12-13-rails-3-1x-migration-change/ Tue, 13 Dec 2011 00:00:00 +0000 https://dchua.com/posts/2011-12-13-rails-3-1x-migration-change/ If you’re on Rails 3.1, you’ll probably notice that the methods in your migration files have changed from ‘up’ and its corresponding ‘down’ to just a simple ‘change’. So don’t be the surprised the next time you handle migrations. Rails 3.1 makes migrations smarter by providing a new change method. This method is preferred for writing constructive migrations (adding columns or tables). The migration knows how to migrate your database and reverse it when the migration is rolled back without the need to write a separate down method. Omniauth - Easy Authentication for your Rails Projects https://dchua.com/posts/2011-02-18-omniauth-easy-authentication-for-your-rails-projects/ Fri, 18 Feb 2011 00:00:00 +0000 https://dchua.com/posts/2011-02-18-omniauth-easy-authentication-for-your-rails-projects/ I just came across this wonderful little gem that makes authentication on your rails application a breeze. This is exactly the gem that I wished was around a year ago when I was developing Baboonza.com (now defunct) and my various mini project sites. Usually when I start a new rails project, I would use Authlogic and tweaked it to allow openid authentication. If you’ve used authlogic before, you would know that the entire process of just installing the gem and getting all your user models and controllers setup is god awful tedious. Create authlogic apps on Rails 3.x easily https://dchua.com/posts/2011-02-07-create-authlogic-apps-on-rails-3-x-easily/ Mon, 07 Feb 2011 00:00:00 +0000 https://dchua.com/posts/2011-02-07-create-authlogic-apps-on-rails-3-x-easily/ Sometime ago, I’ve created a authlogic rails application template to help me create from scratch a rails 3.x app with authentication. This template would generate the necessary models and migration files to get you running in just a few steps. I’ve created this because of an itch. I hate the process of creating a rails application, installing the authlogic gem, editing the various files. While its relatively simple, it gets annoying when you have to do the same steps many times manually. How to consume Project Nimbus dataservices in Ruby https://dchua.com/posts/2010-10-13-how-to-consume-project-nimbus-dataservices-in-ruby/ Wed, 13 Oct 2010 00:00:00 +0000 https://dchua.com/posts/2010-10-13-how-to-consume-project-nimbus-dataservices-in-ruby/ Project Nimbus is a community initiative by developers working in key corporations and government agencies in Singapore that aims to open up data and services for local innovators who wants to create applications with localized data. The project is current supported by a mix of government agencies like LTA, NEA as well as private businesses/startups like Chlkboard and Shownearby. The list is no where exhaustive and the dataset curators are constantly updating their site with new data providers, so please refer to the Project Nimbus page for a more up to date list. Viewing custom/default error pages on development mode https://dchua.com/posts/2010-03-10-viewing-customdefault-error-pages-on-development-mode/ Wed, 10 Mar 2010 00:00:00 +0000 https://dchua.com/posts/2010-03-10-viewing-customdefault-error-pages-on-development-mode/ Working in development environment, we tend to miss out seeing production-level 404, 500 etc. error codes.By changing the following line to false in your config/environments/development.rb config.action_controller.consider_all_requests_local = true We get to display your custom/default error pages instead of an all so information stack trace. Perfectline Blog explains By default, Rails displays the error pages only in production mode. In development mode you get the all-so-informational exception descriptions and stacktraces. This behavior boils down to Rails either considering your request local (and displaying the full debug message) or “remote” (which means the application is probably in production and/or the debug messages should not be displayed). Holding current rails location for future redirection https://dchua.com/posts/2009-11-15-holding-current-rails-location-for-future-redirection/ Sun, 15 Nov 2009 00:00:00 +0000 https://dchua.com/posts/2009-11-15-holding-current-rails-location-for-future-redirection/ I always have this problem of redirects not going back to the exact page that I want it to. After chatting with some of the rails developers at #rubyonrails on freenode, they’ve provided me with this handy code snipplet to save the current page location temporary and after redirecting it, destroy that temporary location. We can return to this location by calling #redirect_back_or_default. def hold_location session[:return_to] = request.request_uri end # Redirect to the URI stored by the most recent hold_location call or # to the passed default.