How to implement Multiple Database(DB) Connection in Rails3

Rails 3In some scenarios, we need data from an external database to execute in different applications. Here, we need a bridge that will connect these two different databases.

In Ruby on Rails, this can be achieved through ActiveRecord’s establish_connection().

Following are the steps to create a rails application which uses multiple databases, where the existing database and the external database will work simultaneously.

Let’s say there are two different rails applications say “myapp” and “remoteapp” where “myapp” depends upon “remoteapp” user table.

Step#1

Edit the ‘database.yml‘ file for the ‘myapp‘ project
Add a new connection for ‘remoteapp‘ as below:

# Connection name, it will be used to connect from myapp
connect_remote:
adapter: mysql2
username: user_name             # username of the remoteapp database
password: password             # password of the remoteapp database
pool: 5
database: remoteapp_db_name    # database name of the remoteapp
host: www.remoteapphost.com      # host name of the db

Step#2

In models folder create a new file called user.rb if it is not already there. Write below code to establish connection with remote app’s database.

class User < ActiveRecord::Base
establish_connection("connect_remote")
end

Here use the connection name defined in the database.yml file in the establish_connection() method.
Like this you can create models to connect with remote databases.
Step#3

It will give you the flexibility for managing users’ data of remote app’s database like it is present in the myapp database.
Use the normal way to get data from the user’s table like

User.all                   #To get all the records
User.find(id)              #To get required record

Here you can also insert or update data in users table by normal way as it is
present in myapp application

#insert new record
user = User.new params[:user]
user.save
 
#update existing record
user = User.find params[:id]
user.update_attributes(params[:user])

The Largest Selling Smartphone in USA Irrespective of Some Flaws

iphoneSince the release of the iPhone 5 and iOS 6, Apple has received mixed reviews for its new operating system as well as the iPhone 5 design.

But it has turned out to be the most popular smartphone in US, Apple has managed to gain around 48% of US market share from the iPhone5. Despite of some faulty applications, iPhone is still popular in US.

New features like a faster processor, taller screen, and slimmer design have definitely played a crucial part in driving the iPhone’s success to nearly half the share in the United States.

Surveys reveal that customer loyalty is also the reason behind Apple’s profound hold on the US market.

Besides the hardware updates, there are other features like Siri, cloud integration with the safari, and Facebook photo-sharing integrations, which works seamlessly with the device.

As expected, the Retina Display is pretty staggering and the A6 chip has improved the performance and speed to a great deal.

With the introduction of iOS6,iPhone application developers have found a better opportunity to explore more features and customization of their codes.

Since its first release, developers around the world are trying to develop applications for iOS6. The Retina display, taller screen, and faster A6 processor allow developers to create stunning applications with high-resolution images and complex functionalities.

Even though Apple’s Map App is filled with flaws and still remains unfixed, it seems to have no effect on iPhone lovers in the US. They solved the problem by using Google Maps instead of Apple’s native navigation app.

itunes-logo

 

 

 

We at Andolasoft develop exquisite iPhone and iPad apps for iOS6 devices. Our experienced iPhone developers use the latest resources to create apps that are engaging and fun. Our apps are rigorously tested to ensure no flaw exists.

Along with development we also release updates for our applications with each improvement in UI and functionalities.  Some of our apps are showcased in App Store which can be downloaded for FREE.

Advantages of Cloud Server over Standard Hosting Server

Cloud DeploymentCloud server is nothing but the virtual server runs on cloud computing environment. Cloud server works like the physical server and can be controlled through an administrator.

It can be called as Virtual Dedicated Servers (VDS). There are various advantages of cloud server over the standard hosting servers.

Scalability:

On Cloud platform you can customize hardware selection appropriate for your application. Eg. Your application may need a small CPU but with high storage or something similar.

But in standard hosting servers you may not have an option to choose what exactly you want, rather forced to choose a pre-defined configuration.

Elasticity:

As cloud is highly scalable you can increase or decrease the hardware needs depending high/low traffic to your application. So, no need to pay unnecessarily for a fixed hosting plan.

Run what you want:

On cloud hosting, you can choose which Operating system you want to run. You can customize the OS as your requirement. But in the standard hosting plan, this option is not available.

Downtime:

On cloud hosting chances of downtime is very remote as multiple servers are used.  In case one server goes down the others takes take care of it and virtually there is no down-time as such. But in standard hosting, if a server goes down then it takes time to resume.

Control Services:

On cloud hosting, you can control your cloud services by the API or from the web-console. This means you can start, stop, increase or decrease any service through API. This feature is not available on the standard hosting server.

Costing:

On standard hosting, we have to choose a plan for ours hosting on a periodical basis (week/ month/year), which is a fixed cost. But in Cloud, just pay as you actually consume. So, cloud-based hosting is cost-effective than a standard hosting server.

Private/Public:

There are several OpenSource apps available to configure the cloud environment. You can set up your own private cloud using cloud apps Cloudstack, Openstack, and Eucalyptus. Also, you can use the public cloud for your application hosting. Eg: AWS, Rackspace, Linode, etc.

How To Migrate CakePHP 1.x To 2.x

Today, we will focus on what we need to do to get CakePHP 1.3 application upgraded to CakePHP 2.2.3-the latest official stable release

Installation

This is pretty straight forward, same as CakePHP 1.3 version.
Download and unzip the CakePHP 2.2.3 and follow these below-mentioned instructions.

Configuration

  • core.php
  • Make sure to copy the security.salt and Security.cipher_seed from your old core.php
  • Take notice of how errors, sessions and caching have changed.
  • database.php
  • There is a minor change on this file,
  • CakePHP 1.3: ‘driver’ => ‘mysqli’
  • CakePHP 2.2.3: ‘datasource’ => ‘Database/Mysql’
  • routes.php
  • Don’t overwrite this file with your older one.
  • You can place your custom routes before or after CakePlugin::routes()
  • bootstrap.php
  • Copy all functions, constants and other code from your old bootstrap into the new one.

Folder Structure

  • The cake folder is now inside lib folder. There is nothing to do with this.
  • Files and folders are now CamelCased instead of lower_underscored
  • Example: The “users” folder inside the View becomes “Users”
  • The controller files are now UsersController.php instead of users_controller.php
  • project_user_controller.php becomes “ProjectUsersController.php”
  • The model files are now User.php instead of user.php
  • project_user.php model becomes “ProjectUser.php”
  • The components files are now FormatComponent.php instead of format.php
  • The helpers files are now DatetimeHelper.php instead of datetime.php

Moved APP files

  • The parent app_classes have been moved and renamed as well.
  • Instead of app_controller.php, app_model.php, and app_helper.php now become Controller/AppController.php, Model/AppModel.php, and View/Helper/AppHelper.php.

Auth Component and Login

  • Auth now supports multiple authorization adapters that can all be used together
  • Cake 1.3.x was automatically checking if user has correctly entered username/password inside your login () method of users_controller but in cake 2.x we need to manually call $this->Auth->login () this returns Boolean value based on successful login or failure.

If you are using “email” as your login field name
CakePHP 1.3: (inside AppController beforeFilter)

$this->Auth->fields = array('username' => 'email', 'password' => 'passw

CakePHP 2.2.3: (inside AppController beforeFilter)

$this->Auth->authenticate = array('Form' => array('fields' => array('username' => 'email', 'password' => 'password')));

Auth Login

CakePHP 2.2.3: (inside UsersController login function)

if (!empty($this->request->data)) {
if ($this->Auth->login()) {
$this->redirect($this->Auth->redirect());
} else {
//$this->Session->setFlash('Your Email or Password was incorrect.');
}
}

CakePHP 2.x auth automatically hashes the password on login but not on save.

We can add a beforeSave() method on the User model to hash the password.

public function beforeSave($options = array())
{
$this->data['User']['password'] = AuthComponent::password($this->data['User']['password']); return true;
}

Request Data

  • CakePHP 2.0 has done some request related changes.
  • The Request Object does not have “form” element any longer.
  • You will need to replace $this->params[‘form’] with $this->request[‘data’] or $this->request->data.
  • $this->data needs to be replaced with $this->request->data
  • So, now we can use $this->request->data on both form submit and AJAX post.
  • Now, we need to check !empty($this->request->data) instead of “!empty($this->data)” while saving a form.

Views Changes

  • Use $this->Html->link() instead of $html->link()
  • Use $this->Form-> instead of $form->
  • Use $this->Session-> instead of $session->
  • Use $this->Paginator-> intead of $paginator ->
  • For JavaScript inclusion use $this->Html->script(“”) instead of $javascript->link()

Moved Email Elements

  • Email elements have been moved from views/elements to View/Emails.

Helpers

  • The Ajax, Javascript, and XML helpers have been removed. You will need to replace these helper calls with appropriate alternatives
  • Helpers can no longer be called with “$helper->function()”. You need to update your helper calls to use $this->Helper->function()
  • If you are loading or importing your helpers inside another custom helper or component,
  • $myhelper = new DatetimeHelper() becomes $myhelper = new DatetimeHelper($this->_View) or $myhelper = new DatetimeHelper(new View(null))

Components

  • All component files should be extended by Component Class instead of Object

DB and Code Caution

  • There is no Enum Support in cakephp2.x as sql server doesnt have similar datatype.
  • You can change enum to tinyint(2)
  • In cake 1.3 used tinyint(1) for is_active database fields.
  • While retrieveing from database it returns 0/1
  • But, cakePHP2.x no longer returns as 0. This will return bool(true) /bool(false)
  • Boolean column values will be casted to php native boolean type automatically.

__() Function and Pagination

  • The __() function no longer has the option to echo. It always returns
  • Change the Pagination code,

CakePHP 1.3:

echo $this->Paginator->counter(array( 'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%'', true)));

CakePHP 2.2.3:

echo $this->Paginator->counter(array( 'format' => __('Page %page% of %pages%, showing %current% records out of %count% total, starting on record %start%, ending on %end%'')));

Christmas Tree Puzzle – A Fun And Relaxing Game At Google Play

At Andolasoft, we love creating the best games for android devices. If you are looking for a relaxing game, you would definitely appreciate the Christmas tree puzzle game developed by our android developers. Your kids would like it for sure!

The game consists of many pieces of a Christmas tree, arranged randomly. While starting the game the user has an option for preview how the tree would look like.

The player needs to drag and drop the pieces and try to set it up until the original tree is formed. It includes a ticking timer to display time taken to complete the puzzle, the faster it is complete, better is the score.

Never miss an update from us. Join 10,000+ marketers and leaders.

As the app is a puzzle and requires focus to complete the game, hence it helps to develop an attitude to set goals and to complete the task in their real life.

It is challenging and keeps the player amused for hours, so this is the game you would like to play. The app has also proved to be a good stress buster for the players.

The sound effects and the music are also pleasing to ears and not to mention it helps putting the player in a relax mood.

It is a simple app for an android phone, but it surely is a fun game for kids and a stress reliever for you after long hours of work on your job. You can download and install this awesome android app from Google Play.

GPB

Andolasoft has been developing fantastic android mobile applications for individuals and from start-ups to established companies. We’ve an excellent team of android app developers providing the most innovative apps as per the requirements. To know more about our cool android apps view the android application development page.

KurrentJobs The Awesome iPhone App To Manage Your Job Search

In this era of Industrialization, everyone is planning to build a company of their own and run a successful business.  But they’re going to need skilled employees to get their jobs done.

Job posting websites could really make their search easy, but with all the available job board options, both recruiters and job seekers are getting frustrated in looking for right choices.

Because job seekers can’t find the right choice of companies as per their skills and experience. As well as the recruiters are getting misled by recruiting consultants and end up with the wrong candidates.

Never miss an update from us. Join 10,000+ marketers and leaders.

As a solution to above problem, iPhone developers at Andolasoft have designed a simple and secure iPhone app named “kurrentJobs”. It acts as a social media job portal for both recruiters and job seekers. It allows individuals, startups and established companies to post jobs as per their requirements.

Jobs are categorized on the basis of skills, experience and on type of jobs like Full-time, Part-time and Freelance.

With this app recruiters can post or manage their job posts from anywhere and anytime. The app is secure with the integration of social plug-ins like Facebook and Twitter.

The app has provided links to recruiter sites and also integrated LinkedIn to help job seekers to apply for jobs. This app can access network communications and storage content on your mobile devices for easier use.

The app is FREE to download and install on your iPhone, from the Apple App store.

iTune

Within a short span of time, Andolasoft has now become one of the major mobile app development companies in USA

We’ve achieved success in developing iPhone apps as we use agile methodologies, innovative work environment supported by creative iPhone developers. For more information about our iPhone and iPad apps please visit iPhone application development page.