Archive for category Ruby on Rails
List of Rails gem that i use often for App development
Posted by admin in Ruby on Rails on May 24th, 2009
I used several gems for different purpose in different applications. After setting up ruby on rails development environment in a new machine, there will be several gems installed by default, such as
activerecord
activesupport
activesource
rake
rubyforge and so on….
These are important gems but i’m not going to deal with these gems now. Most often we need many other external gems for application development. Here i’m providing a list of necessary gems below.
BackgroundRB (For cron jobs in ruby on rails)
capistrano (For automating tasks via SSH on remote servers like software installation, application deployment, configuration management)
pdf-writer (For pdf report generation in ruby on rails)
clickatell (For sending sms)
chronic (For date parsing in ruby on rails)
postgres-pr (For postgreSQL database connectivity with ruby on rails)
ruby-openid (OpenID integration with existing application of ruby on rails)
will_paginate (For pagination)
chris-auto_complete_jquery (Auto complete using jquery)
There are several other useful gems which i’ll include in this list soon.
As a starter application i liked baseapp cause its a great app to start with and it has lots of default features like User authentication including password recovery, account activation, openID integration, will_paginate, admin interface with user management and default CSS-based UI with tabs.
Uninitialized constant ApplicationController and Migration problem in rails 2.3
Posted by admin in Ruby on Rails on May 24th, 2009
Uninitialized constant ApplicationController...... error in rails 2.3
if you have recently upgraded your rails version to 2.3 or higher. you will get this error.
uninitialized constant ApplicationController…..
application.rb was renamed to application_controller.rb in Rails 2.3
To fix this error, rename your application.rb to application_controller.rb
Migration problem in ruby on rails.
During migration i often face problem which says ….syntax error, unexpected ‘\n’, expecting tCOLON2…blablabla
Whenever we use scaffold to develop any simple AMD tool, migration files generate automatically, and we often face such error during migration. we generally think that, those files are ok, but its not always true, you can easily fix those errors and it’s not such a big deal also
open that migration file from db/migrate/file_that_causing_syntax_error.rb
and search for syntax error, you will definitely find few syntax errors there. (generally you will see (comma) is misplaced in several lines).
def self.up
create_table :posts do |t|
t.string, :title
t.string, :body
t.datetime, :mod_date
t.timestamps
end
end
So try to fix those errors and migrate db again. I hope this will help.
Single file migration
You can also migrate a single file, to do this you have to mention the version number of that file, such as
rake db:migrate:up VERSION=20090421094006 (place your own file’s version_number)
rake db:migrate:up and rake db:migrate:down let you run the up and down operations of an individual migration.
You can get help regarding rails migration in the following link (one of my favourite rails migration cheatsheet)
http://dizzy.co.uk/ruby_on_rails/cheatsheets/rails-migrations
Install and run a simple ruby on rails application in windows xp (Netbeans & Instant rails)
Posted by admin in Ruby on Rails on March 1st, 2009
Few days ago i made a blog post regarding ruby on rails installation in Linux machine . But some of my friends told me to write a post regarding ruby on rails installation in windows machine. So here is what you need to do, though I found it little difficult to setup ruby on rails environment in windows
To install ROR in windows xp what you need is listed below
- Instant Rails
- Netbeans IDE
OR
- cRuby Interpreter(C based ruby) or jRuby interpreter (java based ruby)
- Webrick or Mongrel or Glassfish or Apache server.
- Database (PosgreSQL, MySQL, Sqlite, Microsoft SQL server …..)
I like cRuby interpreter and mysql as i’m much familiar with C and MySQL. Ruby on Rails supports large number of databases and one of its main feature is database abstraction (Active Record) which allows one to change full database server anytime he/she wants and you don’t have to change a single line of code in the main application.
Anyway, You can use Instant rails (cRuby & MySQL) for installing Ruby on Rails in windows and Netbeans IDE 6.5 for developing Ruby on Rails application. Netbeans is a standalone IDE and it already comes up with jruby interpreter by default.
So install Instant rails and start mysql service, you don’t need to start apache service as we’ll use webrick server (default) for ROR application. Now install and start netbeans IDE.
Now you need to change ruby interpreter from Tools-> Options-> Ruby now browse ruby.exe file from Instant rails directory (where it was installed, most often the directory is, C:/instant rails/ruby/bin/ruby.exe)
Now in the Netbeans window open a new project, select ruby from category then select Ruby on rails Application from projects. Click on next button, type project name and open that project.
Now run the project from Netbeans window, It will automatically open the project in your default browser (if not, type localhost:3000 in the url of browser). There is a rails console in the Instant rails window, one can use that console to test or manage project too.
Ruby is on rails now. Installation part complete.
Ok, Now i’m considering the fact that ROR(Instant rails for windows) & netbeans IDE installed in your pc, follow the steps below to develop a simple rails application (an AMD tool) using scaffold method.
Step 1: start Instant rails (cruby and mysql) and Netbeans IDE
Step 2: In netbeans window open a new Ruby on rails project. Bunch of files will be created in the project folder.
Step 3: Change mysql database name, username and password (if you want different db name, user and password)
Step 4: Now create the database from netbeans. To do this, right click on the project folder select Run rake task->db->create. This will create the database in mysql.
Step 5: Again right click on the project folder, click generate. Select scaffold from the dropdown, type model name in a singular form (such as post) now in the action field type field names: field type that you want in the application you are developing. In my case its (title and body), so type title:string body:text in the action field. Now click OK.
This will generate necessary files with default code in controller, view, database migration and other necessary folders. In Database migrate->migrate folder, you will notice a file which contains info to generate database tables and fields in the database. Now, to create table with specified fields in the database we need to migrate database to current version.
Step 6: Right click on the project, select migrate database->To current version. This will create db table with specified fields.
Step 7: You are done. Now run the project from netbeans and type localhost:3000/posts (posts is the controller name) in the url of any explorer. you will see your application running.
VOILA!!
Install and run a simple application in ruby on rails (feodra & ubuntu)
Posted by admin in Linux, Ruby on Rails on July 14th, 2008
Here is the Instruction that you have to follow to install ruby on rails. Instead of yum, use apt-get if you are using ubuntu.
Step 1: install ruby yum install ruby
Step 2: Install rubygems yum install rubygems
note: It will ask for installing dependencies, Press Y each time
Step 3: Now install rails gem install rails
You are done. ![]()
Now try to run a simple application using ruby on rails.
Create a folder in any directory (suppose its “myproject”) and our project name is simpleapp so from command prompt go to that folder (myproject).
now type
rails simpleapp -d mysql
i.e: -d mysql is for using mysql database. if u r using sqlite3 then just omit these text.
Anyway, after running this rails it will automatically create all the necessary files with a configuration file for mysql. Go to myproject/simpleapp/config/ directory. You will find database.yml file. Open the file you’ll the configuration for 3 database for 3 different mood. By default it always use development mood. So edit the configuration of development mood.
You will see that, it has configured the database name as simpleapp_development.
Edit this name or create new database in the mysql with this name or the edited db name.
Now we will try to build an AMD(add-modify-delete) tool using ruby on rails. For this initially we will use scaffold feature of ruby on rails.
In the command prompt go to your application directory and type
script/generate scaffold post title:string body:text
Once scaffolding is successful then migrate database. To migrate database type
rake db:migrate
Now just run the server and view your application. In order to run the server type
script/server
After running the server you will see that its listening to the port localhost:3000 or 127.0.0.1:3000 . That means you can view your application in that port of your web browser.
Open firefox and type localhost:3000/posts (posts is the controller name) to see your application.
yup. that’s all done. Isn’t it too simple ?
Recent Comments