To continue with the Rails REST resources and routing, as it is something that entered Rails and really revolutionized it and is holding me back from embracing Yii:
In the routing table you specify:
map.resources :users
Then you have seven actions in the controller that automatically get called:
/resources = resources_url = index action
/resources/:id => resource_url(resource) = show action
/resources/new => new_resource_url = new action
/resources (POST) => create action
/resources/1/edit => edit_resource_url(resource) = edit action
/resources/1 (PUT) => update action
/resources/1 (DELETE) => link_to("Delete", resource_url, :method => :delete) = destroy action
The POST and PUT are managed automatically by forms:
@user = User.new
form_for @user do |f|
This detects that the user is a new record and makes the form POST to the resources controller.
@user = User.find(params[:id])
form_for @user do |f|
This detects that the user is an existing record and makes the form PUT to the resources controller. It adds a hidden input named "_method" with a value of "put".
In the same way, link_to("Create instant user", users_path, :method => :post) would create a link that uses javascript to create a form and post it to the specified url.
It enforces some standards in the controller in that you have standardized names for CRUD actions. You can add actions and map them to methods quite easily:
map.resources :user, :member => [:activate => :get]
You can nest resources without headaches:
map.resources :user, :has_many => :posts
Then your posts controller can be invoked:
user_posts_url(user) = /users/:user_id/posts
Then in the controller you know if the posts action was executed in context of user nesting or not by presence of params[:user_id]. You can add before filters to load the user, etc.
Or do you have an admin user controller separate from the main user controller?
map.namespace :admin do |admin|
admin.resources :user
end
Then in the form, you want it to post to the correct controller:
form_for [:admin, @user] do |f|
f.input :username
f.input :first_name
…
Since the controller’s action names are specified, you can mix in a plugin such as resource_controller or resource_this, or extend a base controller with predefined rest actions, and the CRUD is taken care of. That leaves the views, which take care of themselves if you use the form builder, create your own form builder, or use a plugin like FormTastic.
Hope this is useful, perhaps too much at once. REST is a concept that at first may seem like "why do you need to do that, just define your actions, use the scaffolding" or whatever, but once you learn and use, makes other way feel inefficient and primitive.