Posted by arjunghosh on December 23, 2008
Yeah I know its been long since I have been away. Well lot has happened between my last journey through RubyOnRail’s universe from May 28,2008 to the current date. New Rails 2.0 screencast by Fabio Akita which is unspired by the Creating a Weblog in 15 minutes the original screencast by David Hansson , Newer version of RubyOnRails (v 2.2.2) are out, Rails officially moved to GitHub and supports Git as the VCS of choice, Rails thread safety is in (though how is that actually useful ?), lot of nifty changes in Rails v2.2. So all in all lot of things have been happening.
I will try to be more regular here. In mean time, everyone who twitter and in New Delhi, India can check out the twitter.com/rubyonraildelhi where I have been posting regular rubyonrail updates and local information. You can find me on twitter here at @arjunghosh.
Posted in Uncategorized | Tagged: git, github, personal, rail2.0, rails, rails2.2, rubyonrails, screencast | Leave a Comment »
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:
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
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:
D.) Running the RCov:–
Coverage tests can be run using the command:
Posted in Uncategorized | Tagged: deployment, mysql, rail2.0, rails, rake, rspec, ruby, rubyonrails, setup, svn, TortoiseSVN | 3 Comments »
Posted by arjunghosh on April 18, 2008
Rails is a moving target. Its core is constantly changing. So sometimes it is advisable to “freeze” your rails application so that even if you upgrade and install the latest new version of Rails, it does not break anything in your application.
So first change to your rails application directory:
Then run the following command to freeze this application to the version of Rails that is currently installed on your system:
Now to Unfreezing Rails:
Now say you want to freeze to a different version of Rails.No worries. You can freeze to almost any version. This is how:
rake rails:freeze:edge TAG=rel_2-0-2
And to freeze Rails to the current development version:
Freezing helps us when we need to upgrade.For example, we have a Rails application of version 2.0.0 and froze it to that version. Now when Rails version 2.0.2 came out and say you wanted to upgarde, we can upgrade the frozen version of Rails by:
rake rails:freeze:edge TAG=rel_2-0-2
Now suppose after upgrading, you found that your application is not working properly with this new upgrade. So what do you do? Well not to worry. You can easily downgrade back to the previous version:
rake rails:freeze:edge TAG=rel_2-0-0
Posted in Uncategorized | Tagged: deployment, edge, rail2.0, rails, rubyonrails | 1 Comment »
Posted by arjunghosh on February 14, 2008
We see a very useful feature in Rails 2.0 as defined in Changeset 7422, where now we can generate migration for adding and removing columns by directly passing attribute:type pairs to the migration generator.
Now for example, we need to add a column called ‘dept’ to students table where the model will be called ‘Student’.
Now previously we used something like:-
script/generate migration add_dept_to_student
Now in case of new better way of writing migration in Rails 2.0, we write it as follows:-
script/generate migration AddDeptToStudent dept:string
Here the migration name AddDeptToStudent holds the key. ‘Add’ specifies the we want to add column(s) and ‘Student’ separated by ‘To’ specifies the table.
Similarly, if we need to remove a column ‘dept’ :
script/generate migration RemoveDeptFromStudent dept:string
Similar to above, the migration name RemoveDeptFromStudent holds the key. ‘Remove’ specifies the we want to remove column(s) and ‘Student’ separated by ‘From’ specifies the table.
Posted in Uncategorized | Tagged: migration, rail2.0, rubyonrails | 3 Comments »
Posted by arjunghosh on January 11, 2008
I am very happy with Rails 2.x and the hard work that DHH and Rails core folks put into it. But I have a complain : I would like to complain to DHH and the Rails core team about backward compatibility breakages like say changes in the adapter layer without much regard for backward compatibility. I recently faced an issue where the ASF gem(Sales Force RoR framework connection adapter) would not work with the app I was working on, when I graduated the rails app to 2.x. I was forced to appeal to Sales Force. They were very helpful and in fact Doug Chasman (Principle Member of Salesforce R&D ) replied and they took out the rails 2.x version for the ASF gem. But I had wait for this and this cost time AND the frustration and angst I had to go through :). I understand somethings need to be deprecated, but still care should be taken that working things like gem and plugin don’t suddenly stop due to major changes.
Posted in Uncategorized | Tagged: compatibility, rail2.0, rubyonrails, upgrade | Leave a Comment »
Posted by arjunghosh on January 7, 2008
This post is mostly as a reminder to self. There are some changes in Rails 2.0:-
1. SQLite3 is the new default database. So when a rails app is created, by default the database support, which comes preconfigured, is for SQLite3. Though I am not sure how popular this move by Rails core will be, since most of(like me) us have been using MySql for long and it has some excellent support tools. So anyways, if you still want to create a rails app with MySql support preconfigured, you simply need to do
“rails -d mysql myapp“
and everything is the same as before. “-d” is for preconfiguring selected database. So above command will work for any database adapter.
2.The command to generate RESTful scaffold –
“script/generate scaffold_resource model_name“
no longer works. Instead, you have to do this:
script/generate scaffold model_name
3. In RESTful scaffold, the view files for the various controller actions were given file names such as “edit.html.erb” instead of “edit.rhtml”. The reason is because “.rhtml” has been deprecated in Rails 2.0.
A good link I found on Rails 2.0 changes was by Brad
Of course there is the DHH blog post :).
Posted in Uncategorized | Tagged: hacks, rail2.0, rubyonrails, upgrade | 1 Comment »