Redirect After OmniAuth Sign in With Devise

class AuthenticationsController < ApplicationController
def create
auth = request.env[“omniauth.auth”]
user = User.find_by_provider_and_uid(auth[“provider”], auth[“uid”]) || User.create_with_omniauth(auth)
sign_in_and_redirect(:user, user)



Add the line in bold to redirect!

OmniAuth & Devise: Validation failed email and password cannot be blank

If you are using Devise as the authentication for your Ruby On Rails application and you are looking to implement OmniAuth, that allow the users to login with their Facebook or Google Account.

But once you have all the codes and omniauth setup, on creation you will hit the following error:

Validation Failed: Email and Password cannot be blank.


The issue here is that the Devise model that you are working with will have the following :validatable added as part of the model. This is to validate that the database authentication have both the email and password before creation of the account.

But with omniauth, we may not get the email or do the user need the password to login, they simply use the relevant account for the different providers, such as Twitter, Facebook or Google to login.


We will need to overwrite the default Devise validation. Using the following methods below. Just copy them to your model and you should be good.


def email_required?
super && provider.blank?
def password_required?
super && provider.blank?


Note : provider is a field or column in your model.

Validation failed: Password can’t be blank

Ruby on Rails : preloading data or Loading Massive amount of data

To load data via Ruby On Rails:

1. Create this a file name “import.rake” in the following location: App -> Lib -> Tasks

2. Place your CSV file in the following location: Public -> SeedData (create this folder)

2. This are the codes that should be in the import.rake files, note that the row[1] is corresponding to the CSV column


require ‘csv’

desc “Import a CSV file into Active Record”

task: import => [:environment] do

CSV.foreach(‘public/seeddata/Sample Data.csv’, :headers => false) do |row|
<<Replace this with your model name>>.create( :fullname => row[1], :currency =>row[3])



Rails 4: Dynamic populate field value

I was playing around with Ruby on Rails (RoR) over the weekend and I wanted to populate some textfield on the form base on a certain dropdown list selection. After a couple of hours of research, I managed to piece together how it will work in RoR and I decided to share it here for everyone else who are hunting for the information.

Assuming you have a form, with a dropdownlist and 2 textfields with the selection of the dropdownlist you are going to populate the textfields with the corresponding values.

Step 1: Finding out the ID for the forms elements.
I will ask you to view source on your page and take note of the respective elements. In my case they are as follows:
– Dropdownlist : counter_cid
– Textfield 1 : price_input
– Textfield 2 : date_input

Step 2: Using Ajax & Jquery
Add the following into your View page.

In the script, I basically say on the dropdownlist on change, I will call Ajax to the following URL (i will get to this in Step 4) and the data is the value of the dropdownlist selected. Finally, I tell it that this is a script return type.
<% content_for :bodyJS do %>

<script language=”javascript”>
$(document).ready(function() { $(‘#counter_cid’).change(function(){ $.ajax({url: ‘/counters/currentprice’, data: ‘id=’ + $(‘#counter_cid’).val(), dataType: ‘script’}); }) });
 <% end %>

Step 3: Adding the Method to your Controller file

In your controller file, my case CounterController.rb, insert the following:

This will tell the controller to response to the following format, add this line as the first line in the controller class.

respond_to :html,js

Second, we going to define the method.

def currentprice()
name = Counter.find(params[:id]).name
quote = StockQuote::Stock.quote(name)
@currentprice =

Step 4: Routes.rb
Now we need to configure the routes so that the ajax call could access.

Change your routes to the following:

resources :counters do
collection do
get "currentprice"

After you are done, do a rake routes in your terminal to verfiy that is created.

Step 5: Finally adding in the js.erb file.
This will help us update the value back to the texfield

Browse to the counter folder under App-> Views -> Counter -> Add a new file “currentprice.js.erb”

$("#price_Input").val(<%= @currentprice %>);

Finally you are good to go!

Microsoft Exchange 2010 & .Net Framework 4.5 Issue

Microsoft Exchange 2010 SP 2 stop working with .NET Framework 4.5, email stop working.

By logging in the Exchange Management Console, we will notice that the database is unmounted and you are unable to mount it back on.

To resolve this issue with Microsoft Exchange 2010, you need to update it with the Microsoft Exchange 2010 service pack 3. After which it should start working for you.

Note: Did a further testing on Microsoft Exchange 2010 with SP 1 seems like this issue does not exist.

Not very sure why this is happening and this is the quick fix I figured.


Xcode & Three20 Framework

This article will cover the basic of adding the Three20 framework to your Xcode 4 solutions.

A little background of this particular framework, quoting from the source.

Three20 is a open source Objective-C library used by dozens of well-known brands in the App Store, including Facebook, Posterous, Pulse,, and SCVNGR. Three20 provides powerful view controllers such as the Launcher, the popular Photo Browser, and internet-aware tables.

Another post will be written to discuss about the features of the framework, Three20. But for now let’s us get started on adding this the Three20 to your Xcode 4 project.

Three20 source code could be downloaded from the following link.

I do strongly suggest that you download the tar.gz version.

  1. Start by extracting the content of the file you downloaded from the site.Again, I suggest that you should extract the file on the desktop.
  2. Locate the file at that paticularly path three20/src/script/

    xcode4 three20 facebook

    xcode4 three20 facebook


  3. Open Terminal,
    Enter: python
  4. Drag into the terminal window,
    Enter: -p
  5. Locate your xcode project, Drag the .xcodeproj file into the Terminal.
    Enter: Three20
  6. Check that the Terminal Window should now look something like this
    > python /Users/xxx/Desktop/three20/src/scripts/ -p /TestingProject/TestingProject.xcodeproj Three20 
    Press Enter.

 This will add the Three20 framework into the xcode project and you can find out more on how to use the following at the following site.

Popovercontroller for Iphone

I was searching for a good community control for the popoverviewcontroller seen on the ipad.

I present to everyone, .

It was so simple to get started with the above and you can remove the complexity in the developing customize UI and get along with your actual development work.

Steps to get it working.

1. Add the following files

  • FPPopoverController.h
  • FPPopoverController.m
  • FPPopoverView.h
  • FPPopoverView.m
  • FPTouchView.h
  • FPTouchView.m
  • ARCMacros.h

2. Add the following codes in your IBAction event.

ViewController *content = [self.storyboard instantiateViewControllerWithIdentifier:@"home"];

FPPopoverController *popover = [[FPPopoverController alloc] initWithViewController:content];
popover.arrowDirection = FPPopoverNoArrow;

[popover presentPopoverFromPoint:CGPointMake(, - popover.contentSize.height/2)];

Lastly, do check out the demo included in the git checkout!

Disable Google Chrome Outdated Prompt

Firstly, I am a Big Fan of Google Chrome and its have been my favourite browser choice.

But this little message box on Chrome have been bothering me a lot lately. To remove the outdate prompt do the following:


Append the above to the chrome.exe in the properties of the file.

If you have it pin to the taskbar like me in Windows

1. Unpin the existing shortcut
2. Run the new chrome and pin in back to the task bar.

[UIPopoverController initWithContentViewController:] called when not running under UIUserInterfaceIdiomPad.’

[UIPopoverController initWithContentViewController:] called when not running under UIUserInterfaceIdiomPad.’

I finally got time to start working on some weekend IOS project and I am starting to get rusty with my IOS language.

Started one of my older project and tried to get going but hit an error i thought was pretty base.

Basically this error is associated with the UIPopoverController and you are running the simulator in iPhone mode and not in iPad mode.

Hope that helps anyone who face the same issue.

Xcode : Unknown class in Interface Builder file

Error : Unknown class in Interface Builder file

This error normally occurs when you have more than 1 target and the newly created file (.m) is not in the Complied Source.

To resolve this, access the Targets in your xcode and make sure that the newly created .m file is within the complied source by adding it in.

Do a run again, everything should work fine.