Posted by arjunghosh on March 3, 2009
Just wanted to do a very quick post on this very new hip & cool site on parenting – lil’grams

And do you know what, its has been made in RubyOnRails!
Do check out this site. It the brain child of Greg Narain who is a well know serial entrepreneur & social media expert.
Already people are talking about it and when its yet to be launched!!
Actually people like NYTime, CNET, Mashable have been talking about lil’grams for sometime. Even KillerStartups has a mention.
There is also a buzz on twitter too
Yes, some would say its been in making for quite sometime. But as they say patience has its virtue. Ultimately its a labour of love.
It been really a long journey for me personally too. Have been working on it for quite some time. I still remember those days of sleepless night, long meeting, etc.
Though I am yet to be a dad
(a.k.a am un-married), I too feel like a proud parent my self on the birth of lil’grams which I feel is literally my baby!
If you like (and also dont
) do tell us about it here which I assure will be promptly replied to
Posted in Uncategorized | Tagged: cool, lilgrams, parenting, projects, rails, rubyonrails, website | 2 Comments »
Posted by arjunghosh on February 27, 2009
Well this is essentially a note to self and well to others too.
The best help documents online for Ruby On Rails and Ruby are these AJAXified websites which allows real-time searching of sytanx and commands.
For Ruby On Rails, it is:
And for Ruby, we have:
And the best part is you can even download them so that you can use it offline!
Another good resource for Rails documentaion and help guides is the newly created collaborative effort Rails Guide project. This was started by @lifo as a project to give the rails community a good documentaion which was painfully lacking till now. Since its a collaborative effort, you can participate here. There is even buzz about this project on @twitter
Posted in Uncategorized | Tagged: guides, help, rails, ruby, rubyonrails, tips, tutorials | Leave a Comment »
Posted by arjunghosh on February 17, 2009
The following code will create a temporary file for say attaching a vcard file to email.The following code is dynamic to use ERB as a template to create the file dynamically every time with the variable “telephone”,”location”,”email” which gets binded to the ERB file and is under scope.
The code is:-
{
telephone = “347-27456″
location = “New Delhi”
email = “xyz@gmail.com”
vcard = ERB.new( File.open(‘address.vcard.erb’ ){ |f| f.read } ).result( binding )
f = File.new(“temp_file.vcf”,”wb”)
f.puts vcard
f.close
}
and in pastie is here
Posted in Uncategorized | Tagged: hacks, howto, pastie, programming, rails, ruby, rubyonrails, tips | 1 Comment »
Posted by arjunghosh on December 23, 2008
Model names in RubyOnRails should be Singular. This will create Table name as corresponding Plural names.
You have got to remember that about model naming conventions in rails. .
I know this is a very basic concept in RubyOnRails but sometimes these simple basic concepts are the ones which slip through the cracks.
Example:
> ruby script/generate model Post
This will create a Model by the name “Post” i.e. singular in english language and a migration to create a table by the name “Posts” which is plural form of “Post”.
I have even put this into a pastie for easier remembarance http://pastie.org/345491
Posted in Uncategorized | Tagged: activerecord, conventions, model, Newbie, rails, tips | Leave a Comment »
Posted by arjunghosh on May 28, 2008
Right now am going through a design and Theme sift as the present theme is much better suited to display codes. So please be patient. Thanks
Posted in Uncategorized | Tagged: design, theme, wordpress | 2 Comments »
Posted by arjunghosh on April 29, 2008
This is a quick note to self. Though,I found this excellent post by Chad while looking for something else but this post had a excellent note on browser cache also. So this post is mostly a re-post from Chad’s.
So here it goes:
To ensure that the page isn’t cached by the browser and will always be re-fetched, add a before_filter to the purchases controller which calls a private method on ApplicationController:
before_filter :no_cache,
nly => [:new]
private
def no_cache
response.headers["Last-Modified"] = Time.now.httpdate
response.headers["Expires"] = 0
# HTTP 1.0
response.headers["Pragma"] = "no-cache"
# HTTP 1.1 'pre-check=0, post-check=0' (IE specific)
response.headers["Cache-Control"] = 'no-store, no-cache, must-revalidate, max-age=0, pre-check=0, post-check=0'
end
Now there is a catch – ‘not caching’ only works in Firefox.
Now the above code should have worked for all browser, but it did not work in Safari or in IE 6 and 7. The reason is that any page with an iframe on it will never be cached, and will always be re-fetched.
The solution is iframe. So, we add this to views/foo/new.
<iframe style="height:0px;width:0px;visibility:hidden" src="about:blank"> this frame prevents back forward cache </iframe>
This frame prevents back forward cache. And this works. Now we have cross-browser no-caching in a RESTful. Though this is a hack as Chad says. But it works for me.
Posted in Uncategorized | Tagged: browser, cache, rails, rubyonrails | 5 Comments »
Posted by arjunghosh on April 28, 2008
I am very sure most know about this and is a very simple thing. But as I have found sometimes that small things are the one which are missed.
So wanted a quick note on – How to make the text inside a textarea selectable on mouse click.
Well, we use the Javascript event system
[def: An event in Javascript is something that happens with or on the web page ].
Specifically we use the onclick Event to achieve the above stated goal. onClick applies to buttons (submit, reset, and button), checkboxes, radio buttons, and form upload buttons.
This is how we do it:
<textarea rows="3" cols="43" name="none" onclick="this.select();">This is the text which when clicked on will get selected</textarea>
The main syntactic sugar here is the “onclick=”this.select();”
Here the “this” helps us to access the textarea object and then we fire the DOM event “select()”
dynamically on it, which in turns selects the text inside the textarea.
ciao until next time
Posted in Uncategorized | Tagged: css, events, html, javascript, programming | 4 Comments »
Posted by arjunghosh on April 25, 2008
A.) How to setup a Rails 2.x Application on your local system:–
[NOTE: The following steps are for Windows OS environment]
- Setup Ruby and Rails on the local system:-
- Install Ruby on Windows:
The easiest way is using the One-Click-Installer
Once the installation is complete, check that path to ruby\bin directory is in your PATH variable (Run “cmd”, then type “path” at the prompt and check that the path is there.
The great thing about the one-click installer is that it comes with Ruby Gems, Scite pre-installed. The thing to watch out for is that one-click installer does not have the very latest version of Ruby, so when you are reading Ruby Docs, make sure you know which version of Ruby you have (run “ruby -v” in the command prompt)
- Installing MySQL on Windows:
First, download and run the latest MySQL. After the files are unzipped, an Instance Config should run automatically (you can run it manually at any time from your MySQL bin directory just run “MySQLInstanceConfig.exe”). Then go through the step as directed.
- Install Rails on Windows:
Run the following command: gem install rails –-include-dependencies
(If this command gives you an error, you do not have the latest version of gems installed. Run “gem -v” to check for the version of RubyGems. It should be 0.9.4. Otherwise, you may probably need to update RubyGems as well.: gem update –system [NOTE: It is recommended that RubyGems version 0.9.4 is used as Rails 2.x had some issue with version 0.9.5. Though this issue had been subsequently resolved]
- Installing SVN on Windows:
We use the TortoiseSVN SVN client on our local machine to use SVN.
We have SVN version on our local system: 1.4.3
The SVN version installed on the Server, which we were using, can be found by running the command on the server: svn –version
- Create a rails 2.x application:-
SQLite3 is the new default database. So when a rails 2.x application is created, by default the database support, which comes preconfigured, is for SQLite3. So to create a rails 2.x application with MySql support preconfigured, you simply need to run the following command: rails -d mysql testapp
This will create the skeleton structure for the rails 2.x application with mysql database adapter.
- Configuring the database for the application:-
Now a database.yml file is created in the /config under your application root folder. You need to set the development, production and test database names there. Also you need to put in the database password,if there exist any,So for your database in this .yml file. This password is same as the one you put in while installing mysql on your machine.
- So for a rails application, database.yml file configuration is as follows:
development:
database: testapp_development
adapter: mysql
encoding: utf8
username: root
password: mypassword [Note: password is set here if any]
socket: /tmp/mysql.sock [NOTE: Similarly for production and test database]
- To create the database on the local machine:-
Run the following command: rake db:create:all
The above command will create all the three database i.e. development, production and test database as set in the database.yml file
If you want to start from scratch, you can do rake db:drop:all And in the middle of development we can do rake db:rollback to undo the latest migration file.
- To seed the database with initial database:-
Run the following command: rake db:populate
This will populated the database with initial data as written in populate rake file. Also a rake task called rebuild has been created so that it becomes easy to do the above steps from dropping a db, re-creating the db,running all the migration and then finally populating it with the initial seed data.
Run the following command:rake db:rebuild. [NOTE:This rebuild rake task will easily do all the above db related steps. See my previous post for “How to create a rake db:rebuild task”
- To run your Rails 2.x application on the local system:-
Need to first go to root folder of your rails application. For example: F:/Projects/testapp/trunk
Then run the following command: ruby script/server
This will run the application in development mode. To run in production mode: ruby script/server -e production
- To install rspec plugin for rails application:-
Run the following commands at the command line:
ruby script/plugin install http://rspec.rubyforge.org/svn/tags/REL_1_1_3/rspec
ruby script/plugin install
and http://rspec.rubyforge.org/svn/tags/REL_1_1_3/rspec_on_rails
Once the plugin is installed, you must bootstrap your palnglue rails app with RSpec. Stand in the root of your Rails app and run: ruby script/generate rspec
This will generate the various files needed to use RSpec with Rails.
- To run the rspec with rake on the local machine:-
Run the following command at the root folder of the application: rake spec
or run specs with scripts/spec command: ruby script/spec spec
B.) How to install a Plugin for Application:–
Stand in the root of your rails app and run:
ruby script/plugin install <here the url path of the plugin to be installed>
C.) Running the RSpec test cases for Models:–
Run using the command:
rake spec:models
D.) Running the RCov:–
Coverage tests can be run using the command:
rake spec:rcov
Posted in Uncategorized | Tagged: deployment, mysql, rail2.0, rails, rake, rspec, ruby, rubyonrails, setup, svn, TortoiseSVN | 3 Comments »