Storing a simple student database in Rails

Set up Ruby on Rails from http://rubyonrails.org/download. Make a directory ‘my_rails’ in your home folder for rails applications.
$ cd my_rails

create your application as following
$ rails new student_db
$ cd student_db
For including gems, you need to update the Gemfile, that resides in your application folder. Open the ‘Gemfile’ and update.

Gemfile :
source ‘http://rubygems.org’
gem ‘rails’, ‘3.0.0’
gem ‘sqlite3-ruby’, ‘1.2.5’, :require => ‘sqlite3’

Specify the version number for sqlite3.    This is for avoiding confusion while installing the gems.

Install gems
$ bundle install

Now you are ready to generate the student model. Use scaffold generator.

Student data model

Note : Rails developers dislike scaffold. Because it itself generates code. So don’t use it. This is only for referring the application.
$ rails generate scaffold Student first_name:string last_name:string roll_no:integer total_mark:integer

Migrate the database using rake.

$ rake db:migrate

Now run the server.

$ rails s

open the browser and go to http://localhost:3000/student

To see this application visit,
Student_data_base

Advertisement

Author: Abhilash

I'm Abhilash, a web developer who specializes in Ruby development. With years of experience working with various frameworks like Rails, Angular, Sinatra, Laravel, NodeJS, React and more, I am passionate about building robust and scalable web applications. Since 2010, I have been honing my skills and expertise in the Ruby on Rails platform. This blog is dedicated to sharing my knowledge and experience on topics related to Ruby, Ruby on Rails, and other subjects that I have worked with throughout my career. Join me on this journey to explore the exciting world of web development!

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: