rails Escaping special characters like & in rails Html views Safely escape and render html characters while preserving special characters like ampersand(&) using strip_tags and Loofah
rails Letter opener is not processing emails in rails app letter_opener is one of the most useful gems out there for a rails developer. The configuration is pretty much easy and straightforward. But yet I stumbled upon a situation where it stopped working. All the setup instructions were in order, but still, for
rails How to fix the Index name too long error in rails migrations Today, I was reviewing some legacy code, trying to isolate the bottlenecks and pinpoint the optimisation strategies for scaling and performance optimisations of a rails app. As the usual procedure, I wanted to check the database indexes and see if something was missing here.
SQL Find out which part of your code is triggering ActiveRecord or SQL queries. Today, I got a new pet project to play with and my job was to identify the bottlenecks and performance improvements we can make in the application. So I wanted to jump in and wanted to see what SQL queries were being triggered when
devops Manage sidekiq workers using deployment setup and Capistrano In real world, most of the Rails applications would be having a Sidekiq instance as its companion in production systems. And it's a necessary thing to have some sort of mechanism to manage your Sidekiq instance with your deployment setup. In this post, I
rails How to turn on SQL debug logging for ActiveRecord If you want to see the SQL queries that your apps are running and want o optimize them or tune them, then it is a nice idea to log them. You can either log it to your log file or even to STDOUT. You
API How to enable support for CORS with custom headers like authentication in Rails I was building a client side application for my API that I built using Rails/Grape. So in order to access the resources using the API from the client application the first thing that I need to do was to enable CORS support in
rails How to fix Incomplete response received from application from nginx / passenger in a rails application I was trying to deploy a simple rails application( stack is Ruby 2.2.4, Rails 4.2.5, with passenger/Nginx as application/web server) to AWS EC2 and I was getting a weird error. Incomplete response received from application And looking at
ruby Active Model Serializer vz Jbuilder vz Rabl vz Grape-entity for rendering JSON When architecting an API only application one the of the most important points of discussion among the team members is which framework to use ? Should we be using Rails and render JSON ? Should we be using Grape ? Should we be using Rails-API ? Also, how
ruby Error handling with Grape, Rails and ActiveRecord CanCan I have been working on a project developing the backend API using Rails and Grape. One fine morning I pulled the latest code from the git repo that my colleague wrote, and was going to review the code. As usual, the first thing I
grape Using helper methods and helper modules in Rails Grape to keep the code DRY I was working with a Grape API and got into a situation where I was kind of reimplementing some methods on more than one mounted API. So naturally, I wanted to refactor the code, keep it DRY and extract it as helper methods and
rails Rails : Devise : Send different Emails for Confirmation based on the presence of attribute or parameter So what am I up to today? - I thought of scribbling down some pieces of code that I wrote to help one of my interns in my company to help complete a task. I was juggling with my daily work and I suddenly
rails Testing carrierwave file uploads with RSpec and FactoryGirl. TLDR; In this blog post, I am gonna focus only on testing carrierwave. So if you are looking for instruction on installing/setting up carrierwave in your project I would suggest you looking at the carrierwave's wiki over here. So let's assume we have
ruby Connecting Ruby & Active Record Without Rails require 'active_record' require 'mysql2' # or 'pg' or 'sqlite3' # Change the following to reflect your database settings ActiveRecord::Base.establish_connection( adapter: 'mysql2', # or 'postgresql' or 'sqlite3' host: 'localhost', database: 'your_database', username: 'your_username', password: 'your_password' ) # Define your classes based on the
rails Creating tables and problems with primary key in Rails If you run into the following error when running a migration in your legacy Rails app with MySQL 5.7 or above rake aborted! "Mysql2::Error: All parts of a PRIMARY KEY must be NOT NULL:" the fix is by monkey patching
ruby Pundit for authorization with Rspec Rails Authorization is one of the important feature of any web app. With rails you can leverage the power of all those wonderful open source gems that are available to you or you can code your own authorization module. The most commonly used gems for
git “bin/rails: No such file or directory” w/ Ruby 2 & Rails 4 on Heroku Rails apps with version 4 or above has some files under the bin folder namely bundle, rails, rake, setup, spring. But since I had bin folder gitignored, these files dint make it to heroku. To fix this: Remove bin from ~/.gitignore Run bundle install
ruby Calling View helper methods from Controller / Model in Rails Recently I was researching a way to use link_to inside my Rails 3 controller, and learned about the method view_context. So if you ever want to access view helper methods from controller / models in rails 3 you have to use view_context
til How do I make --no-ri --no-rdoc the default for gem install? If you are deploying to a server, or you do not want to wait around for rdoc and ri to install for each gem, you can disable them for gem installs and updates. Just add the following line to your ~/.gemrc or /etc/gemrc: