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

<code>

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])
end
end

</code>

 

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.

Scenario
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 %>

<% 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 = quote.bid
end

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"
end
end

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.

HTH

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, Meetup.com, 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. www.three20.info

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 ttmodule.py at that paticularly path three20/src/script/

    xcode4 three20 facebook

    xcode4 three20 facebook

     

  3. Open Terminal,
    Enter: python
  4. Drag ttmodule.py 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/ttmodule.py -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(self.view.center.x, self.view.center.y - 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:

–allow-outdated-plugins

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.