How To Implement Event Calendar In Rails App

Event calendar is a way to show multiple, overlapping events across calendar days and rows. This is an interface to add events, edit events, & destroy event. In Rails there is a gem/plugin “event_calendar” to implement it just like Google calendar.

The following steps demonstrate the implementation of event_calendar in both Rails 2.3.x and Rails3.x environment.

Step#1 –

Installing the gem/plugin

  • In rails 2.3.x

Install the required plugin from below path

script/plugin install git://github.com/elevation/event_calendar.git

Generate the necessary static file and example

script/generate event_calendar
  • In rails 3.x

Install the required gems

gem 'event-calendar', :require => 'event_calendar'

Run “bundle install

You can also use as a Plugin, to install plugin

rails plugin install git://github.com/elevation/event_calendar.git

Generate the necessary static file for the event calendar

rails generate event_calendar

Step#2

Include the necessary style sheet & java-script into your layout/view

<%= stylesheet_link_tag "dialog","fullcalendar","jquery-ui","style" %>
<%= javascript_include_tag "jrails1/fullcalendar.js","jrails1/jquery-
ui.js","jrails1/gcal.js","jrails1/jrails.js","jrails1/jquery.validate.js"%>

Step#3

Create a migration file to add necessary columns as follows

class CreateEvents < ActiveRecord::Migration
def self.up
create_table :events do |t|
t.string :name
t.datetime :start_at
t.datetime :end_at
t.timestamps
end
end
def self.down
drop_table :events
end
end

Step#4

Add the necessary paths to the “config/routes” file

  • In Rails 2.3.x
map.calendar '/calendar/:year/:month', :controller => 'calendar', :action => 'index',
 
:requirements => {:year => /d{4}/, :month => /d{1,2}/}, :year => nil, :month => nil
  • In Rails3.x
match '/calendar(/:year(/:month))' => 'calendar#index', :as => :calendar, :constraints => {:year => /d{4}/, :month => /d{1,2}/}

Step#5

Change the Event model to add the calendar as follows

class Event < ActiveRecord::Base
has_event_calendar
end

Step#6

Modify the Calendar controller as follows

class CalendarController < ApplicationController
def index
@month = (params[:month] || Time.zone.now.month).to_i
@year = (params[:year] || Time.zone.now.year).to_i
@shown_month = Date.civil(@year, @month)
@event_strips = Event.event_strips_for_month(@shown_month)
end
end

Step#7

You can also override the events method in helpers/calendar_helper.rb

module CalendarHelper
def month_link(month_date)
link_to(I18n.localize(month_date, :format => "%B"), {:month => month_date.month, :year => month_date.year})
end
# custom options for this calendar
def event_calendar_options
{
:year => @year,
:month => @month,
:event_strips => @event_strips,
:month_name_text => I18n.localize(@shown_month, :format => "%B %Y"),
:previous_month_text => "<< " + month_link(@shown_month.prev_month),
:next_month_text => month_link(@shown_month.next_month) + " >>"
}
end
def event_calendar
calendar event_calendar_options do |args|
event = args[:event]
%(<a href="/events/#{event.id}" title="#{h(event.name)}">#{h(event.name)}</a>)
end
end
end

Step#8

Add the following code to display the calendar in the view file

<%= event_calendar %>

See Also: Security Checks you must do before Rails App release

I hope it helps you. Planning anything in Ruby on Rails? Get in touch with Andolasoft experts. Feel free to give your valuable feedback.

How To Generate Barcode Using Barby Gem In Rails 2.3.8

A barcode is a series of vertical black lines with white spaces in between. This series of lines and spaces can be read by a device that can decode them. This would be a barcode reader.

In Ruby on Rails there is a gem called “barby” which generates the barcode with various format.

Here is an example to create barcode using barby & Rails 2.3.8.

Step#1

Include the barby gems in your config/environment.rb file

config.gem'barby'
config.gem 'barby-chunky_png'
config.gem 'png''RubyInline'

Install the gems by running the commandrake gems:install. Restart the Rails server.

You might face problem to start the server after the gems installed.Comment out the gems “png” & “RubyInline” in the “config/environment.rb” to get the server started.

Step#2

Create a folder named “Barcodes” to store the barcode images in your “Public” folder.

Step#3

Add the below lines of code in your controller

require'barby'
'barby/outputter/png_outputter'

Step#4

The following method will generate the barcode images and store in the “/public/Barcodes” path. Place this method inside the controller.

The “symbology” is the format in which the barcode will be generated. Default is “Code128B”, If you want to generate in different format you can set the “symbology” according to it.

def generate_barcodes(data) # check to see if we don't already have this barcode image uri = CGI.escape(symbology) + '_' + CGI.escape(data) + '.jpg' fname = RAILS_ROOT + '/public/Barcodes/' + uri #fname = '/var/www/html/arc_cloud/arcdevelopment/' + uri
 
# if the barcode image doesn't already exist then generate and save it
if ! File.exists?(fname)
 
str = 'Barby::'+symbology+'.new("'+data+'")'
 
begin
barcode = eval str
rescue Exception => exc
barcode = Barby::Code128B.new(data) # fall back to Code128 type B
end
 
File.open(fname, 'w') do |f|
f.write barcode.to_jpg
end
 
end
uri
end

Step#5

Following lines of code will call to generate your dynamic barcode
generate_barcodes(@item_id)

Step#6

To show the Barcode images call the following lines of code

<img src="/Barcodes/<%= @job_info.job_number %>.jpg" >

How to shorten URL using “bitly.com” in Rails 3.x

rorURL shortening is a technique on the World Wide Web (WWW) in which a Uniform Resource Locator (URL) may be made substantially shorter in length and still direct to the required page.

This is achieved by using an HTTP Redirect on a domain name that is short, which links to the web page that has a long URL. This is especially convenient for messaging technologies such as Twitter and Identical which severely limit the number of characters that may be used in a message.

Many web developers pass descriptive attributes in the URL to represent data hierarchies, command structures, transaction paths or session information. This can result in URLs that are hundreds of characters long and that contain complex character patterns. Such URLs are difficult to memorize and manually reproduce. As a result, long URLs must be copied-and-pasted for reliability. Thus, short URLs are more convenient for websites.

Step# 1

  • To begin with, create an account at bit.ly “
  • Get your API key by the following URL

“http://bit.ly/account/your_api_key/”

Step# 2

  • In rails 3.x

Write the following gems in your gemfile

gem 'bitly'
  • Run “bundle install”

Step# 3

Add the following code in your controller

require 'bitly'

Step# 4

Bitly recently released their version 3 API. From this 0.5.0 release, the gem will continue to work the same but also provide a V3 module, using the version 3 API. The standard module will become deprecated, as Bitly do not plan to keep the version 2 API around f orever.

To move to using the version 3 API, call in you top of the controller:

Bitly.use_api_version_3

Step# 5

To shorten a URL

bitly = Bitly.new('your-bitly-user-id','your-bitly-api-key') page_url = bitly.shorten('your-url') shorten_url = page_url.short_url

It will generate the bitly URL similar to “http://bit.ly/7BWXcQ”

Creating an Engine on Refinery CMS

Refinerycms

‘Engines’ are nothing but ‘plug-ins’ which adds up extended functionality to the existing Refinery application. Engines installs in the “vendor/extensions” folder in a refinery app.

Engines will create a tab in the Admin panel of the Refinery CMS to control the information on the engine.This example demonstrates creating an engine in an existing refinery app. The environments used are Ruby 1.9.3, Rails 3.2.8 & Refinery cms 2.0.8.

Step#1

To create an engine, just execute the below command

rails generate refinery:engine engine_name attribute:type attribute:name

NB: The engine name should be in singular which will generate the structure in plural form.
For example we want a FAQ engine for our CMS which will be controlled by CMS admin

rails generate refinery:engine MyFaq question:string answer:text

Running the above command will create a new folder “extensions” under “vendor” directory and in the “extensions” the new engine “my_faqs” will be created.

Step#2

After that run the below commands to make it executable

bundle install
rails generate refinery:my_faqs
rake db:migrate
rake db:seed

Step#3

Restart the server to get the effect. You will find the new tab “My Faqs” has been added both in the menu section of the user section and admin section.

Login as Admin to manage your FAQs

How to customize an engine during creation?

Creating the engine with a namespace

rails g refinery:engine MyFaq title description:text --namespace FAQ

Creating the engine by skipping the frontend pages

It will add menu and form page in the admin section only. User section will be omitted

rails g refinery:engine MyFaq title description:text --skip-frontend

Web Site and Server Monitoring with Nagios

Nagios since it’s inception in 1999 has become one of the most popular and open source monitoring system (under the free license GNU General Public License) to monitor IT infrastructure problems.

It alerts you about any critical problem that might occur in your infrastructure through e-mail, SMS and pager.

Installation and configuration of Nagios is comparatively simpler than other infrastructure monitoring tools.

Although numerous plugins are available in the internet to monitor different services and for graphing of the data, plugin can also be customized as per your requirement by using tools like shell scripts, C++, Perl, Ruby, Python, PHP, C#, etc. DuringNagios configuration you have to keep the following in mind.

  • Lines starting with ‘#’ character are considered as comments and are ignored while processing.
  • Inconfiguration lines the characters that appear after a semicolon (;) arealso treated as comments hence are not processed.
  • Directive names are case-sensitive.

To get data from the monitoring host’s you will need aNagios agent. Below are some popular Nagios Agents:

  • NRPE
  • NRDP
  • NSClient++

Below are some protocols used for monitoring:

  • SMTP
  • POP3
  • HTTP
  • NNTP
  • ICMP
  • SNMP
  • FTP
  • SSH

Below are some Host resources which can be monitored:

  • Processor load
  • Disk usage
  • System logs

Kick off Your Small Business with Magento Go

With internet prevailing its effect on every corner, businesses got the chance to spread across the world.

Once a small cotton factory is now the biggest ready-made clothing supplier of the world and this is not a single instance as there are millions like this.

Keeping that legacy alive, Magento development platform launched the online eCommerce building platform Magento Go. It lets you develop an online store for your small business with very much less investment.

And the best thing is you don’t need to be a techno-buff for this due to its simplest operations and easy learning interface.

Magento introduced a SaaS (software-as-a-service) version of its e-commerce platform named Magento Go. It allows small businesses or merchants to build easy-to-use shopping portals for customers around the world.

If you’re thinking of setting up an online store for your various product ranges, then it can help you build your store with your designs.

Magento Go include some basic features like Order Management, Customer Analytics and some cool features like Coupons and Gift Cards, which were not available in the Magento Community edition.

The designs, impressive templates, product flexibility, and search engine friendliness are some of the major features in Magento Go.

Magneto Development team recently updated additional features to Magento Go for merchants of the United Kingdom like Royal Mail Shipping, UK Cookie law compliance, improved PayPal payments, VATs and many more.

A trial out period of 30 days is available which can be then subscribed with fewer cost plans to run your e-commerce business. Customer engagement majors like assisted shopping, product comparisons, and wish lists are also taken to make the interactions more useful.

It Connect which is a market for a place for other Magento Go plug-ins is available for merchants who want to add additional features to their stores.

It is really going to kick off your small business if you know optimal utilization of the resources available to reach the maximum number of people.

At Andolasoft we’ve got expert developers on Magento development who have broad experience over handling individual projects on Magento. We have been developing the best quality, highly scalable websites for small to large scale enterprises.

Whether you’re a start-up eCommerce business or a large retailer switching to eCommerce, we can help you by building search friendly and secure websites as per your requirements.