Re: Rails versions and documentation, confused learning rail

Nathan Esquenazi
Sat, 09 Feb 2008 00:42:48 -0000

I will do my best to explain what REST (specifically the rails version
which is one implementation of the overall principle) means to me.

For me, when I contrast REST development to non-REST development, only a
few things stand out. However, to understand REST in rails you must also
understand developing in rails in general.

Nevertheless, the two big REST differences in my opinion come down to
thinking of an application as being ''resource'' oriented. In
other words,
''resources'' are the focal point of any REST application. A
resource can
be anything (either database backed or not) that contains information
used in the application. "Posts" or "Users" or
"Schools" or whatever
else you represent digitally can be a resource.

A RESTful application is all about creating, updating, deleting, and
displaying these resources in a variety of formats and based on a
variety of criteria. This is where the notion of CRUD comes in.
Essentially, thinking of an application as applying a small set of
actions to various resources.

What are the actions applied? Well, this is where the REST actions come
in. RESTful rails is all about keeping the application structured with
conventions on how resources are handled. Most notably, the actions are:


SHOW - a specific is shown to the user with detail in some format
NEW  - a user is presented with a method to add a new resource
CREATE - the actual method responsible for creating a resource
EDIT -  a user is presented with a method to change details for a
resource
UPDATE - the actual method responsible for updating the data for the
resource
DESTROY - a method responsible for deleting resources
INDEX - a list of resources is shown (either all resources or a subset
of them)

These actions are the basic cornerstone of any RESTful rails
application.

The combination of thinking in terms of resources, using conventional
actions, and usually providing several formats for any data make up the
major aspects of RESTful development.

Of course, because you are being a good boy, Rails will provide you with
a plethora of conveniences to reward you.

For instance, REST makes routing easy:

map.resource :posts

will automatically create all the routes to all your various CRUD
actions and appropriately name the urls so you can easily reference them
within the application.

Also, REST will provide a consistent interface which allows creating
API''s rather easily. The whole idea of REST is to be able to provide
data responses in HTML or in JSON or in XML or in RSS, etc based on the
users needs and allowing them to read and modify resources in the
application.

Hope that helps a little bit,

- Nathan
--
Posted via http://www.ruby-forum.com/.