concept location in category rails

This is an excerpt from Manning's book Flexible Rails: Flex 3 on Rails 2.
What will be different about pomodo? For one, its UI will be in Flex, so we can create a cool-looking To Do list with little effort. Second, it will be a Getting Things Done(GTD) style To Do list, meaning that tasks will be organized into projects and will have locations. In addition, pomodo will use the concept of a Next Action, which is essentially the next task in each project that has nothing blocking it.
Listing 6.35. app\controllers\locations_controller.rb
... # PUT /locations/1 # PUT /locations/1.xml def update @location = current_user.locations.find(params[:id]) respond_to do |format| if @location.update_attributes(params[:location]) flash[:notice] = 'Location was successfully updated.' format.html { redirect_to(@location) } format.xml { head :ok } format.xml { render :xml => @location } else format.html { render :action => "edit" } format.xml { render :xml => @location.errors, :status => :unprocessable_entity } end end rescue ActiveRecord::RecordNotFound => e prevent_access(e) end # DELETE /locations/1 # DELETE /locations/1.xml def destroy @location = current_user.locations.find(params[:id]) @location.destroy respond_to do |format| format.html { redirect_to(locations_url) } format.xml { head :ok } format.xml { render :xml => @location } end rescue ActiveRecord::RecordNotFound => e prevent_access(e) end ...
Now that we can add tasks with a name and notes, we’ll add the ability to list and to create projects and locations. This will involve a lot of copying-pasting-modifying of code we’ve already seen for tasks, so we’ll keep the explanations brief.
On the Rails side, the ProjectsController and LocationsController already have create methods that can send XML when that is the requested format, so there is nothing to do there. We’ll start by modifying the ProjectsListBox and the LocationsListBox to display the projects and locations. First the ProjectsListBox; see listing 6.11.
Listing 6.14. app\flex\com\pomodo\events\LocationEvent.as
package com.pomodo.events { import flash.events.Event; public class LocationEvent extends Event { public static const LOCATION_CREATE:String = "locationCreate"; public var location:XML; public function LocationEvent(type:String, location:XML) { super(type); this.location = location; } } }