How to send Push Notifications from server to devices.

What is Push Notification ? Push notification is a feature that allows an app to notify user of new messages or events, even when the user is not actively using your application. Like on Android devices, how a whatsapp message will make a sound and icon appear in the status bar. What is Apple Push Notification service(APNs) ? "Apple Push Notification service" is the service for implementing the push notification feature for IOS devices. How it works ? Each device establishes encrypted IP connection with the service and receives notifications over this persistent connection. If a notification for an application

Reusable code snippets

Hello Everyone, I have reviewed my application and extracted out few methods, which we can reuse in other applications if required. To normalize url def normalize\_url(url) url = url.strip /^http/.match(url) ? url : "http://#{url}" end Display image and default image if image is breaking def display\_image(object) default\_image = "/assets/default_image.jpg" on\_error\_pic = "this.onerror=null;this.src='"+ default\_image +"';" image\_tag object.pic.url(:style), alt: "", onerror: on\_error\_pic end Time in HH:MM:SS format def time\_in\

Draw architectural design of the project using "railroady" gem

As a developer no one likes to write a complete documentation for a project. Butsometime we have to give some document which explain at least our architectural design of project. If in future anyone else work on same project then he can easily understand the overview and business logic before look into the code.We should draw a simple architectural design of our project models, controller and their relationship. There is a gem which provides all necessary diagrams - add it into development group. gem 'railroady' System Requirements $ sudo apt-get install graphviz run $ rake diagram:all It generates all diagrams

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

We should use acts_as_paranoid recursively based on requirement.

First of all I would like to inform that [acts_as_paranoid gem][1] is not updated for rails 4. So in our project we have used [paranoia gem][2] which is similar to acts_as_paranoid. Few days ago we faced a issue like once I archived a object then the associated object also deleted because of dependent: :destroy and I was recovering archived object but all details with the associated objects were lost. Example: We had model structure like this class Person acts_as_paranoid has_one :assets, as: :attachable, dependent: :destroy has_many :members, dependent: :destroy has_

Importing CSV and Excel in rails 4 and ruby 2.0

You can use a single gem 'roo' for reading all types of file, instead of rubyXL, spreadsheet etc. multiple gems for different files(.xls, .xlsx). You can check [here railscasts][1] for importing csv and excel import in ruby 1.9.3. But this code snippet is not working with Ruby 2.0. As [this episode][2] used gem 'roo' for reading files and gem 'roo' has been updated for rails 4.0. So you need to do some code changes to work [it][3] with rails 4.0 Changes are: In Method: self.open_spreadsheet(file) Csv.new(file.

redactor-rails - Rich Text Editor

redactor-rails has a advantage like no need to see preview of html contents. Add gem gem 'redactor-rails' Add to your application.js: //= require redactor-rails Add to your application.css: *= require redactor-rails and in your input field need to add a class: "redactor" thats it. You can integrate carrierwave with this to save images in apFor more see documentation :https://github.com/SammyLin/redactor-rails

Avoid rails helper times_ago_in_words()

Let's say we have 100 records in lessons table then %td.last_modified= times_ago_in_words(lesson.updated_at) server calculate the time ago for each record for each request, it wastes a lot of time on server side. If we replace above code by %td.last_modified"= lesson.updated_at.to_s and load jquery plugin <script src="jquery.timeago.js" type="text/javascript"></script> then in JavaScript $("td.last_modified").timeago() thats it. Then the javascript will calculate the time ago on client side after loading

Upgrading Rails 4

Upgrading Rails 3.2 to Rails 4 You’ll need to be running Ruby 1.9.3 or later Create New branch $ git checkout -b rails4 Gemfile Changes: Replace: gem 'rails', '3.2.x' with: gem 'rails', '4.0.0.rc1' Rails 4 removes 'assets' group, so remove assets group and change the gem version included in assets compatible to rails 4 like: gem 'coffee-rails', '~> 3.2.1' => gem 'coffee-rails', '~> 4.0.0.rc1' gem 'less-rails' gem 'sass-rails', '~> 3.2.3' => gem 'sass-rails', '~> 4.0.0.rc1' gem 'uglifier', '&