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'}

Send notification to flowdock-group from rails application

If you want to send any notification message from your rails application, its easy to send it with following steps: To send notification to your flowdock group, you will need email-address of flowdock grouYou can get it from flow-settings of your group. example: "xxxx@xxxx.flowdock.com" In your application, define mailer class and send email-message to above email. class UserMailer Thanks.

apipie-rails gem: best documentation tool

Apipie-rails is a DSL and Rails engine for documenting you RESTful API. Instead of traditional use of #comments, Apipie lets you "describe the code by code". This brings advantages like: It uses ruby syntax Reusable doc for other purposes (Best for validations) Easier to extend and maintain apipie-rails gem owner has documented it in very nice way with examples. Refer [Github Documentaion(github doc)][1] Path to documentation: The documentation is available right in your app (by default under "/apipie" path.) Also you can provide your own path using initializers. For more information refer [here(config

Code Review

Code Review Hello Everyone, I have reviewed a codebase of one of our projects. It was a good experience. Few good things. Really clean code. Small methods. I had to travel 5 months back commits to find some bad code. :) Things to improve on: Found less specs, But it is possible that specs have been covered already. Overall Thoughts: The code is super clean, liked it!. fantabulous work folks! Snippets: Code: Menu.pluck(:hyphenated_name) Suggestion: This can be moved to class method which can be cached instead of firing the queries in the app again and again, one problem

XML Parsing with Ruby

In one of the projects(ACES), we came across a functionality: to parse huge(50mb+) XML files. Here efficiency was very critical piece, as file size was huge. Also we wanted the results of parsing quickly for further analysis so the effective time was less and application performance was unhampered. We chose SAX Parsing Technique(DOM vs SAX) There are two ways to parse an xml file, DOM and SAX. SAX being more efficient as it process the xml file incrementally, thereby memory utilization is minimum. Whereas a DOM parser, builds a tree representation of the entire document in memory

Example usage of Redis - LUA script in Rails

This topic is about using Redis and LUA script in Rails. Before proceeding, you may like to read [ Introduction to LUA script with Redis][1] Redis doesn't have any command to calculate total number of keys We'll use [zrangebyscore][2] to find number of members between index range. Instal [redis-rb][3] Start rails console Prepare a dataset based on timestamp > t10 = 10.minutes.ago => 1386935151 > t20 = 20.minutes.ago => 1386934568 > t30 = 30.minutes.ago => 1386933971 > t40 = 40.minutes.ago => 1386933374 This is non-realistic data, may vary for you. Populate redis with Sorted Set > redis = Redis.new # initialize redis => # zadd -

Things which Rails could do but I didn't know.

Run Helper methods in the console $rails c => helper.number_to_currency(100) => "$100.00" => helper.time_ago_in_words(3.days.ago) => "3 days" Shorthand Migrations $ rails g resource person first_name:string last_name:string email:string token:string You can write above command as- $ rails g resource person first_name last_name email token Both will generate same migration: class CreatePeople Add Indexes to migrations $rails g resource person first_name:index last_name email:uniq token class CreatePeople true end end Add Associations to migrations $ rails g resource company person:references name description:text We can

Lessons learnt and Good Practices

There are several practices followed in Rails. Since ruby is the backbone of rails, here are few practices that are recommended: Lets consider a class ABC: class Animal attr_accessor :id, :type def self.mouse(object, a1, a2) puts "#{self}" end def animal puts "I m in animal instance method" yield if block_given? end def id @id.to_i end def initialize(id, type) @id = id @type = type end def update_extra_attrs(a1, a2) puts "#{self.inspect}" end end Execution & Explanation: To change the behaviour of attribute's value, always make use of ruby's getter and setter methods.

Crawling and Scraping Techniques in Ruby

Problem case to solve : Crawl any given site(url), scrape each page uniquely for content from given selector or Xpath Available options for Crawling and Scraping : With [libxml2][1] [Nokogiri][2] is one of the fastest HTML/XML parser. Almost all of the scraping tools written in Ruby such as Mechanize, Wombat, Anemone, etc. uses Nokogiri as there base DSL for sraping. [Mechanize][3] - Is a beast in this category. It efficiently uses Nokogiri for HTML scrapping. Do see Abi's post on [Automating browser navigation's through Script][4] [Wombat][5] takes the scraping term to a next higher level,

Cheat Gem to Get Cheats.

This gem is not something that you are going to use in project, However, This will help you to get all the cheatsheats, that will help us in getting up to speed. Setting up cheat gem gem install cheat The first command u need to try out is the sheets cheat cheat : How to use cheat gem cheat sheets : Show list of available lists in console. This will give u a list of available sheets like: git, cucumber, rspec, svn, ssh, loose_weight etc. The list is also growing continuesly How to use this, cheat git cheat cucumber If you