How to customize Devise authentication in Rails3?

Rails31Devise is an authentication solution for Rails application development. Since devise is an engine and all the files created by it are packaged inside the gem. We need to invoke some generators in order to customize it according to our choice.

Configuring views:

  • If you want to modify the views generated by devise, then you just need to invoke the following generator, and it will copy all views to your application.
rails generate devise:views
  • If you have more than one role in your application (such as “User” and “Admin”), Devise offers an easy way to customize views. Just write the following line inside your “config/initializers/devise.rb”
config.scoped_views = true
  • Now you will be able to have views based on the role like “users/sessions/new” and “admins/sessions/new”. You can also use the generator to generate scoped views like below:
rails generate devise:views users

Configuring controllers:

If the customization at the views level is not enough, you can customize the controller generated by devise using following steps.
Step#1

  • Create a custom controller
class Users::SessionsController < Devise::SessionsController
[Your code goes here]
end

Now you can customize your methods according to the conditions.

Step#2

  • Now tell the route to use this controller in “config/routes.rb”
devise_for :users, :controllers => { :sessions => "users/sessions" }

ustomizing Error Messages:

Devise has its own error messages that are shown when something goes wrong. All of these messages are stored in a locale file (config/locales/devise.en.yml), making it easy to maintain them. Here you can see the list of error messages created by devise and you can customize them according to your choice.

Customizing Registration process:

You can also customize the registration process of devise. Here is an example to explain the customization of Registration process where devise sends an activation email automatically after a new user registration happens.

Step#1

  • Modify the “users” migration file created by devise. Uncomment the block of fields under Confirmable.
t.string   :confirmation_token
t.datetime :confirmed_at
t.datetime :confirmation_sent_at
t.string   :unconfirmed_email

Step#2

  • Customize the “User” model like below:
devise :database_authenticatable, :registerable,:recoverable, :rememberable, :trackable, :validatable, :confirmable

We have added “:confirmable” module for devise to the model. Confirmable is responsible to verify if an account is already confirmed to sign in, and to send emails with confirmation instructions. Confirmation instructions are sent to the user email after creating a record.

Then add the field names that are defined in step#1 to the ‘attr_accessible’.

Step#3

  • Run the migration
rake db:migrate

Step#4

  • Now set the default URL for according to your requirement in “config/enviroments/development.rb”
config.action_mailer.default_url_options = { :host => 'localhost:3000' }

Now if you register for a new user then devise will send a confirmation email with required instructions.

Android to be used in Consumer Electronic Appliances Too

android31Google’s Android operating system is the most widely used Smartphone operating system in the world. Besides that, it is considered as the most user-friendly OS by android users and has released it to other mobile device manufacturers.

But now Google has decided to power consumer home appliances with its android based software.

These android applications will be developed specifically to the instrument that will be embedded to its hardware.

Embedding Android directly into devices will make it easier for electronic appliances to exchange information with humans. For example, android powered television can show a pop-up message from the kitchen, indicating that the dish is ready to be served.

The user could remotely access the kitchen appliances to turn it OFF or ON, from the TV. Google’s step is to bring future imagination into reality. This will save a lot of time for the users and may avoid possible dangers.

Like, if the device detects a gas leak in the kitchen it can automatically turn the appliance off or intimate the user about the situation. Devices will also be able to detect intrusions in the house when the user is not present.

Making such intelligent, connected appliances will need experienced android developers at the forefront.

This advancement will also need advanced android application development for creating custom apps for the instruments. At Andolasoft we develop the most intriguing android applications for our customers.

We have a pool of expertise android developers to provide innovative solutions for all versions of android operating software.

Android’s Fragmentation – Still A Problem For Android Developers

android1Google’s Android possesses a major flaw in its OS development, which is a fragmentation issue. For this reason, one android OS version still remains isolated from other androids OS version.

It offers a wide range of hardware and software options for the developers, which in turn increases the time of development and causes complications for application design.

From the latest survey of devices in the last two weeks, Google found that only 10% of android owners are running the latest version of the OS, and almost half (47%) are still using “Gingerbread” i.e. the version 2.33.

Android Developers have been challenged by Android’s open nature from the beginning. In addition, the release of OS updates to all the available hardware is dependent on a wide range of sources.

For such reasons, Android developers have now targeted their Android application development for devices that run the Gingerbread platform and later, which is now on over 80% of Android devices.

Mobile Developers have faced even the worse fragmentation issues during the early days of development. With numerous hardware variants, developing an app for a group of devices was almost impossible.

With Android, the fragmentation issue is more troublesome because of the advanced features which only a fraction of devices support it. This situation continuously drives the developers to focus on the hardware-specific abilities of smartphones.

At Andolasoft we develop the most intriguing android mobile applications for individuals and from start-ups to established companies.

We have team of experienced android developers who are skilled to develop innovative apps for all versions of android devices. Some of our apps showcased in the Google marketplace at:

https://play.google.com/store

/apps/details?id=com.andolasoft.christmasdemo&

feature=more_from_developer

How To Convert Documents To PDF in PHP?

‘Unoconv’ is the tool to convert doc, Docx, ODT to PDF file in PHP.

‘Unoconv’ is a command-line utility that can convert files from any ‘OpenOffice’ supported formats to a different ‘OpenOffice’ supporting the format.

Installation Required:

  • OpenOffice and Unoconv

You can provide one or more files as arguments to convert each of them to the specified output format.

Example:

unoconv -f pdf  example.doc

bove command will convert the example.doc to example.pdf in the current working directory.

Some other commands are:

unoconv -f odt example.doc
unoconv -f doc example.odt
unoconv -f jpg example.odt
unoconv -f xsl example.csv

Apple IPhone Smartwatch Is Expected In This Year

In this current year is supposed to see some amazing technological innovations. This would be the year of wearable smart devices and compact gadgets. From recent news, it is now revealed that tech giants like Apple have decided to develop a smartwatch.

It will be developed to facilitate easy access to Apple devices like the iPhone and iPad. And it is also expected to be available during this year.

‘Apple’ has teamed up with ‘Intel’ to create this Bluetooth-equipped wearable smartwatch to sync operations and notifications with the iPhone.

It would allow the users to remotely access the phone from their wrist, without necessarily holding the phone when needed. That means the users can send text messages, make calls, and update their Facebook status directly from their watches.

With an embedded Siri- integration and a 1.5in display, an iPhone compatible smartwatch is definitely in high demand.

It is expected to run a certain version of iOS for which it will give more opportunities to the iPhone developers around the world. This new device assumed as the ‘iWatch’ would be a hot favorite among the phone lovers in this year.

At Andolasoft we develop the most intuitive iPhone Applications for our customers. Our experienced developers keep updating their skill set with the latest technology and iOS releases to match the competitive market.

File Uploading Through Paperclip in Rails 3.x

Rails3Paperclip is an easy file attachment library for Rails Applications. Attached files are saved to the file system, database or cloud and referenced in the browser by an easily understandable specification.

Here is an example to explain the image attachment for a user profile in an application. This example narrates about saving the image in the file system. However, the images can be saved in S3 bucket [Amazon Simple Storage Service, S3] or database.

Step#1

ImageMagick must be installed in the system and Paperclip must have access to it. ImageMagick is a software suite to create, edit, compose, or convert bitmap images. It can read and write images in a variety of formats. You can download it by visiting the following URL:

http://www.imagemagick.org/script/index.php

Step#2
Include the paperclip gem in your Gemfile

gem "paperclip"

Then run the bundler to install the gem

bundle install

Step#3
Add the fields for the image processing as below in your migration file

class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :photo_file_name
t.string :photo_content_type
t.string :photo_file_size
t.timestamps
end
end
end

Then run your migration files

rake db:migrate

Step#4

Modify the user model for cropping and save image in your system folder

has_attached_file :photo, :styles => { :small => "150x150>" },
:url => "/system/:attachment/:id/:style/:basename.:extension",
:path => ":rails_root/public/system/:attachment/:id/:style/:basename.:ex

Here you can specify the file path and the image size as per the requirement.

Step#5
Modify your view file to upload an image

<pre class="plain plain">&lt;%= form_for :user,:url =&gt; {:action =&gt; "create"}, :html =&gt; { :multipart =&gt; true } do |f| %&gt;
&lt;%= f.file_field :photo %&gt;
&lt;% end %&gt;</pre>

Step#6
Write the following code to display the image of a user

<%= image_tag @user.photo.url (:small)%>

Please stay connected with us by subscribing our email.
Also feel free to share your opinions in the comments section below: