Categories
ruby on rails

thin on windows

Read about thin for a while (faster than webrick, faster than mongrel), but didn’t really get the chance to try it out, until recently.

As I am looking for moving my little rails application out of instantrails to a proper production environment, decided to give thin a spin, too bad Passenger isn’t supporting Windows platform, heard a lot of good thing about it too.

Installing thin server on Windows isn’t quite straightforward though. Thin actually consist of mongrel parser, EventMachine, and rack, but the latest EventMachine gem is not win32 binary release, that pose a lot of problem for the installation.

There are a few workarounds suggested on the net,
from Winston

  • install rack with the usual gem install
  • install EventMachine gem 0.8.1 as local gem
  • install thin gem install thin –ignore-dependencie

But this didn’t quite workout for me, some suggested to install MinGW and MSYS, then the normal path of gem install thin should just work. Tried that, but fail as well.

Then found out that EventMachine has a binary release at 0.12.6, and with that it works right away for me, here are the steps that did it for me,

  • gem install rack
  • gem install eventmachine-0.12.6-x86-mswin32-60.gem (download gem to local, and install locally)
  • gem install thin

Only after a full circle of searching around the net, that I found out these steps are actually mentioned in the comments by Marty McGee in winston’s original post. Duh.

Categories
ruby on rails

clearing rails console

And so not to forget this again.
This is how to clear the console screen in rails, type this,
In Ubuntu,

system 'clear'

In Windows

system 'cls'

from stackoverflow

Categories
ruby on rails

Import Excel data with FasterCSV

So I have a whole list of data which is already in excel and need to put into the Rails application. I could either manually type them into the database, or there must be some plugin out there dealing with this.

Just a quick google bring me to Unixmonkey blog talking about fastercsv.

All you need to do is just

gem install fastercsv

Then copy the excel file(oh, convert it to .csv file first) to the root of your application.

Now as the target table is “Bcode” with fields, term_no, standard_termĀ  at the root, ruby script/console

require 'fastercsv'
FasterCSV.foreach("#{RAILS_ROOT}/file.csv") do |row|
  record = Bcode.new(
  :term_no => row[0],
  :standard_term => row[1]
  )
  record.save
end

That is just a few simple line of codes, but believe me, it got me almost 5 times of trying before I got everything right in the console. It is just so frustrated. And only after all that suffering that I find the line saying we can actually put this into data migration script. Arghhh…..

It did take a while (almost 10 minutes, I think) to load in all the 17K rows of cvs data though.

Categories
ruby on rails

Rails collection_select helper

The explanation from api.rubyonrails.org is rather baffling for a newbie like me,

collection_select(object, method, collection, value_method, text_method, options = {}, html_options = {})

Still managed to get the dropdown menu working for my application after searching through the web. There are already quite a few useful resources available in the net for helper method collection_select.

But I seem to lost in the code again looking back at it after a while. And am too lazy to look through all the stuff again. So I try to make a diagram to put down what I already understand from those resources. Might not be the best or complete explanation, but just try to help myself to be able to view it and quickly get a grasp of it.
collection_select_explain_3

Categories
ruby on rails

A year later…

I sort of giving up my own design, for now. I find myself tinkering with the layout and design more than actually writing something here, and that really tell if you look at the last post on the blog, almost a year ago.

I lost count of the time I start and stop my learning of Ruby on Rails, and so this time, I just force myself to start a small project in the company. No more creating fictional project, but this is real application that gonna be used by real people. What motivate you more than working on a real Rails project, huh?

Nothing too complicated though, just a tool for user to punch in some data and get an auto generated partnumber according to certain criterias. But I guess is a good starting point.

There might be another more interesting project that involved graph and some graphic manipulation which could branch out my Rails learning, but let’s complete one thing at a time.