MVC in Rails3

Hai friends,

Today i learned something abt MVC in rails. MVC means, basic over all  functions like  (i.e) Model, View, Controller under the /app  folder in a rails project.

For Ex:

Model,View, Controller (MVC)


After creating a rails project,  if we created a table name like ‘User’ ( $ rails generate scaffold User name:string address:text mail:string ) In the url we called this ‘User’ like ‘users’ (note the plural form) {}

When we hit the url bar, Rails routed this http function into Rails router.

In the Rails project the router function file is in under config folder.{$ gedit config/routes.rb}

'routes.rb' file

This file routes the index into Controller.

In controller folder, their is file called as users_controller.rb

In this file contain, that ‘index’ part.

'app/controller/users_controller.rb' file contains the 'index' part

The index part is like as “def”

In this controller file contains, “User.all” method. here the “.all” is in-built method. This method is assigning into “@users”. This @users are under in “model” folder. Here the “user.rb” file contains, pre-written ruby program like “ActiveRecord” This Activerecord is group of pre-written program, which contains many “def” and “class”.

here Rails inherit the Class “User” into this “ActiveRecord” . This activerecord is very important in ruby on rails, which store the data’s in the DB.

model/user.rb => inherit into ActiveRecord

This user.rb file ‘ll take/store the data from/to the DataBase like MySql or Squlite.

Now the “model” (i.e user.rb) redirect the stored data to the “Controller” (i.e users_controller.rb)

Again this “controller” redirect to the “View” part. The view folder contains some files like “edit.html.erb,_form.html.erb,index.html.erb,new.html.erb  show.html.erb”

Here the “index.html.erb” file contains the view part of the embedded ruby program. Here you can see the program like html.

app/views/users/index.html.erb => View program file

Finally this file convert the output into “html” format and redirect into “controller”

Now, the Controller Redirect into Browser.

Then only we were seeing this output.

http: => final output

this is the simple discription about (MVC) Model View Controller

That’s all !!! Enjoy !!!   If you have any doubt feel free to ask me.


One thought on “MVC in Rails3

Leave a Reply

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

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

Google+ photo

You are commenting using your Google+ 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