I am developing a little application within instantrails, suppose to work in an intranet environment.
The application let user book a part number, by filling some information. For better user experience, I plan to capture the username at the other end that make the booking, instead of creating another layer of login feature and require the user to login again. There is no complex authentication needed, just capture the username and store it together with other information.
ENV['user'] will give you the username that has the rails application running, which is not what we want.
ENV['remote_user'] return nothing at all.
I read through quite a few discussions on the net, it seems like apache didn’t actually pass the remote_user value to mongrel, hence rails application couldn’t call out remote_user. To fix that, we will need to modify on the apache configuration file, httpd.conf, and .htaccess. Admittedly, I really know close to nothing about the setup of these files, and have a hard time following the suggested steps, as to where to add the suggested line of codes, which file to modify, etc, etc.
So I figure, if we forgo apache in the setup, will it be easier to fetch the remote_user value directly from mongrel? or from thin if it is the web server being used.
But still, I just couldn’t get it working.
Is there any gem or plugin need to be installed before this remote_user tingy can be pass to rails application?
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
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,
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.
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
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.
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.

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.