Clear Redis cache and Solr indexes

As I am working in an app which needs keys to be stored in Redis and index data in Solr, due to redis eviction policy, sometimes keys gets evicted, but index in solar remains same, which result in confusing local behavior for me. To clear local redis copy, I do it from redis-cli: $ redis-cli 127.0.0.1:6379> FLUSHDB OK 127.0.0.1:6379> FLUSHALL OK 127.0.0.1:6379> exit To remove Solr indexes, I use curl: $ curl http://localhost:8982/solr/update?commit=true -d '**:**'

Integrating datepicker and timepicker with active admin

In one of our apps, the requirement was having a datetime field which will allow user/admin to select date and time in active admin. So the very first option which I had that was to use existing gem, http://github.com/saepia/just-datetime-picker But this gem doesn't seem to be maintained since last year, so this option was ruled out! The next option was creating DateTimePicker manually using gem "jquery-ui-rails" and then adding .js and .css.scss files in active-admin, this solution was also not working for me! We found one gem gem 'pickadate-rails' documentation can be

Integration of WebUI-Popover in Active Admin

Recently we have used WebUI-Popover plugin in Active Admin. It is a lightWeight popover plugin with jquery. It can be use with bootstrap, but bootstrap is not necessary! Browser compatibility for this plugin is ie8+,Chrome,Safari,Firefox,Opera. We need jquery1.7.1+ for this. Steps For adding WebUI-Popover are: Download from https://codeload.github.com/sandywalker/webui-popover/zip/1.1.2 Extract zip folder go into src folder copy jquery.webui-popover.css this file and paste in app/assets/stylesheets of your project. Same for jquery.webui-popover.js paste in app/assets/javascripts in your "active_admin.

Prepared statements in Rails

Rails 3.1 and above has an awesome feature of prepared_statements. The basic idea behind prepared statements is to compile SQL statements once and cached for it future use. In other words - The benefit to prepared statements is that the database does not have to compile a query plan for every piece of SQL sent to it, potentially saving a lot of time. Checkout an excellent blog(blog) to know more on prepared_statements. Recently, I had to get raw sql from AR object so that I can pass it to EXPLAIN statement to get total number of

Nokogiri gem installation issues on Mac OSx with Ruby 2.1.5

On our Mac OSx, if we upgrade to latest Ruby 2.1.5 (or even 2.1.2) then there are high chances that we will face issues installing nokogiri gem. We might face errors like: ERROR: Failed to build gem native extension. Following are the steps to resolve these issues on Mac OSx Install library libxml2 using brew. brew install libxml2 Read complete error dump on console while doing bundle or bundle install. We will notice that there are useful tips to fix this on our OS, for example for building Nokogiri with a packaged version of libxml2-2.9.

Integration of Redactor Rails in Active Admin

In our current app, there was a requirement to have a nice editor which will provide the basic functionalities like bold,italic and also image upload. We decided to use redactor-rails gem Github-Documentation-Link(Github Doc) . So i took following steps: In Gemfile i included: gem 'redactor-rails' Then for image uploading and storing i included two more gems as: gem 'carrierwave' gem 'mini_magik' Bundle it. rails generate redactor:install rails generate redactor:config In application.js //= require redactor-rails In active_admin.scss on the top include: *= require redactor-rails In ActiveAdmin model i wrote: f.input :name, input_html: {class: 'redactor'}

Launch your website as mobile web application

Are you looking for way to launch your website as a web-app for mobile users? Yes it's possbile.. Recently, I am developing an ember.js application. We are using ember.js (using ember-cli) in our client application and in backend we are using ruby-on-rails. Here we are designing our ember app for mobile users, developing it's UI more responsive for all mobile, tablet and desktop users. Now along with that we want our users to use it like a web-application instead of just browsing it on mobile-browsers. So we did it in following: For Android Users: In your main page

Use Jquery - document.ready() to load page specific javascript in Rails App

Yesterday I was working on one of our portal (It's in Ruby on Rails and we have used quite alot jquery as well). Was integrating a nice Photo Gallery plugin on one of the page. Applcation is having many pages. Every page has some different behaviour and we have different jquery calls for that as per need. For a performant application, we always want to avoid any unwanted calls to different methdods/functions. In my case, as I mentioned earlier I wanted to show Photo Gallery on a page and photo gallery loads as soon as page is loaded. Gallery

Customizing Devise authentication, to check for active Chargify subscription

This post is an extension of article. I added further customization to check if user has active chargify_subscription and then only proceed to login otherwise show custom message instead of default devise message. Here is what I did (2 step process). In our user model (specifically user_extensions) override devise method active_for_authentication as follows def active_for_authentication? super && locked? && active_subscription? end Calling super first is very important here, to have devise perform all its regular checks first and then upon success we can proceed to add our custom checks. locked? is

Configuring database_cleaner

Recently I added few integration tests in my projects using Capybara and Selenium webdriver and ran into banging my head against inconsistencies with test database. I create some records in test DB which were completely invisible to Selenium-driven browser-based tests. The problem is: the tests are being wrapped in database transactions, so any code running outside the actual test process (like, say, a server process servicing a Selenium-driven browser request) does not see the database records. Here are the steps to fix this problem - First of all, and this is very important, go into spec/spec_helper.rb and