Jump to content
Banner by ~ Ice Princess Silky
  • entries
    4
  • comments
    9
  • views
    2,812

I <3 Ruby on Rails


Neikos

1,384 views

blog-0065559001355341990.png

Ruby On Rails

 

Ruby on Rails is an application framework, written in Ruby and whose mainly purpose is to help ease the workflow of an MVC oriented website.

 

MVC = Model - View - Controller

 

This is the base of RoR (Ruby on Rails), and pretty much the main reason to use it (instead of other frameworks.)

 

A Model is anything that holds values, you could think of them as 'objects'. Although that is not quite accurate as models can also be a relation between two other Models. They are often represented by one column in the database. ( Although 'virtual' models exist as well. )

 

Here is an example:

 

A Forum User has a Name, Password, Settings, Posts, Signature, Avatar.

 

 

So it's model would be something like this in Rails:

 

 

ss%20%282012-12-12%20at%2008.27.29%29.png

 

attr_accessible is a security feature with which you can specify which attribute can be 'mass-assigned'. That means you update them all at once instead of having them individually. ( Mostly for convenience as it saves you from typing a lot. )

 

the lines 'has_one' and 'has_many' do exactly what it says, it tells rails that there is a setting that belongs to this User. There are also many posts that belong to this User.

 

 

 

 

A Controller is the application logic, it is what allows you to specify what an user is allowed to do. What he can see, etc...

 

For example let's consider a Forum Model, it has many Threads.

 

Here is an example of a Threads controller:

 

.png

 

 

params is a hash where you have the parameters of the page.

 

With http://example.com/threads/1 the params hash would hold as an ":id" variable the number 1 which is the id of the thread model.

 

 

 

It all reads pretty much like English so it should be straightforward.

 

 

 

A View is what is displayed to the user. In it you can use Ruby ( by default it uses ERB as it's templating system ) to change the appearance of what you want.

 

 

Here is an example of my upcoming website:

 

.png

 

This is the Roleplay Creation page. As you can see I use HTML & Ruby interleaved.

 

 

 

So this is why I love Ruby on Rails, if you want to do a resource oriented website it just fits the job perfectly. It's 'magic' is always the right way, especially if you are beginning.

 

I highly suggest this Framework to anyone starting into Web Development as it only beneficial. You learn a lot simply by shaping your application the 'rails way'.

 

Stay tuned for more!

 


 

 

 

If you wish to dive into Rails I highly suggest this tutorial:

 

http://ruby.railstutorial.org/ruby-on-rails-tutorial-book

 

It covers anything you need to know to start out.

  • Brohoof 2

3 Comments


Recommended Comments

This isn;t much different like frameworks in other languages, this is similar to using Java Spring or using .NET MVC4 framework.

 

Using MVC is great though.

Link to comment
  • Founder

ERB looks just like PHP "templates" without the parentheses that are common to C-like languages. :P

 

This is a great and concise overview of the Rails framework at its most essential level, Neikos. Laravel, the PHP framework I'm currently working with, looks awfully similar to Rails and no doubt was partly inspired by it.

 

I personally like the look and feel of PHP better, as well as the ease in deploying it on my infrastructure (cPanel takes care of installing and updating it, as well as managing your extensions and restarting crashed/hanging processes), but have every intention of seriously diving into Ruby and RoR sometime. From the look of your sample code, it should be pretty easy to jump in because of its similarities to Laravel. :)

  • Brohoof 1
Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Join the herd!

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...