资源说明:Tiramizoo Courier app
h1. Tiramizoo web app Web application for customers to order deliveries and for various roles to sign up and maintain their profile and see stats. h2. Infrastructure * Rails 3 (web app framework) * Mongoid 2 (Document oriented data store) * Cream (Roles etc.) * Devise (Authentication) * CanCan (Authorization) * Slim (Template system) https://github.com/stonean/slim "Haml to slim":https://github.com/fredwu/haml2slim h2. Setup Rails Wizard (tiramizoo) "Rails project creation wizard":http://railswizard.org/f8c0bcd629a3378401cb "Rails project":http://railswizard.org/f8c0bcd629a3378401cb @rails new APP_NAME -m http://railswizard.org/f8c0bcd629a3378401cb.rb -T -O -J@ h2. Mongo HQ 1. Confirm your MongoHQ database settings In this example, we will assume your database is named fancy_pants and that the port that MongoHQ assigned to you when you created your database was Port 27021. 2. Make sure you have a MongoHQ database user set up on your database You will need to have a database user set up on the database that you want to connect to. For this example, we will assume the username is admin and the password is sekret.MongoMapper.connection = Mongo::Connection.new('hatch.local.mongohq.com', 27021, { :logger => Rails.logger }) MongoMapper.database = 'fancy_pants' MongoMapper.database.authenticate('admin', 'sekret')*Mongo HQ connection* "MongoHQ for Heroku users":http://support.mongohq.com/discussions/community-tips/2-logging-in-to-mongohq-for-heroku-users$ heroku addons:remove mongohq:free --app tiramizoo-beta $ heroku addons:add mongohq:free --app tiramizoo-beta_Add remote connection_ on Mongo HQ$ heroku config --long --app tiramizoo-beta MONGOHQ_URL => mongodb://heroku:0oymh4rkyqotfle3uuo4sw@flame.mongohq.com:27077/app399236Open Mongo HQ account and add a remote connection. Paste in the MongoHQ_URL from heroku log, and choose any database (that you already created on Mongo HQ) Then the Web app on Heroku should be working! h2. Geocode "Geokit and Rails":http://railsmagazin.de/geokit-rails-und-google-maps-teil-1-552 "Google maps in a Rails app":http://blog.yangtheman.com/2009/08/27/how-to-integrate-google-maps-in-a-rails-app/ h2. Locales See _ApplicationController_ !!! Every helper method dependent on url_for (e.g. helpers for named routes like root_path or root_url, resource routes like books_path or books_url, etc.) will now automatically include the locale in the query string, like this: http://localhost:3001/?locale=ja. You may be satisfied with this. It does impact the readability of URLs, though, when the locale “hangs” at the end of every URL in your application. Moreover, from the architectural standpoint, locale is usually hierarchically above the other parts of the application domain: and URLs should reflect this. You probably want URLs to look like this: www.example.com/en/books (which loads the English locale) and www.example.com/nl/books (which loads the Netherlands locale). This is achievable with the “over-riding default_url_options” strategy from above: you just have to set up your routes with path_prefix option in this way: # config/routes.rbscope "/:locale" do resources :books endNow, when you call the books_path method you should get "/en/books" (for the default locale). An URL like http://localhost:3001/nl/books should load the Netherlands locale, then, and following calls to books_path should return "/nl/books" (because the locale changed). If you don’t want to force the use of a locale in your routes you can use an optional path scope (donated by the use brackets) like so: # config/routes.rbscope "(:locale)", :locale => /en|nl/ do resources :books endWith this approach you will not get a Routing Error when accessing your resources such as http://localhost:3001/books without a locale. This is useful for when you want to use the default locale when one is not specified. Of course, you need to take special care of the root URL (usually “homepage” or “dashboard”) of your application. An URL like http://localhost:3001/nl will not work automatically, because the root :to => "books#index" declaration in your routes.rb doesn’t take locale into account. (And rightly so: there’s only one “root” URL.) You would probably need to map URLs like these: # config/routes.rb @match '/:locale' => 'dashboard#index'@ Do take special care about the order of your routes, so this route declaration does not “eat” other ones. (You may want to add it directly before the root :to declaration.) Sven Fuchs’s _routing_filter_ and Raul Murciano’s _translate_routes_. See also the page How to encode the current locale in the URL in the Rails i18n Wiki. One source of client supplied information would be an Accept-Language HTTP header. People may set this in their browser or other clients (such as curl). A trivial implementation of using an Accept-Language header would be:def set_locale logger.debug "* Accept-Language: #{request.env['HTTP_ACCEPT_LANGUAGE']}" I18n.locale = extract_locale_from_accept_language_header logger.debug "* Locale set to '#{I18n.locale}'" end private def extract_locale_from_accept_language_header request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first endh3. RSpec 2 setup In Gemfilegem "rspec-rails", ">= 2.2.0"Run generatorscript/rails generate rspec:install"Test Devise with Rails 3 and RSpec2":https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Rails-3-and-RSpec h3. Cucumber "Test Devise with Cucumber":https://github.com/plataformatec/devise/wiki/How-To:-Test-with-Cucumber h2. Textmate bundles "HAML":https://github.com/flov/HAML-TextMate-Bundle "Slim":https://github.com/fredwu/ruby-slim-textmate-bundle h2. Validations "improved-validations-in-rails-3":http://omgbloglol.com/post/392895742/improved-validations-in-rails-3 "validates_rails_3_awesome_is_true":http://lindsaar.net/2010/1/31/validates_rails_3_awesome_is_true "sexy-validations":http://thelucid.com/2010/01/08/sexy-validation-in-edge-rails-rails-3/ h2. CAPTCHA "Recaptcha with Devise":https://github.com/plataformatec/devise/wiki/How-To:-Use-Recaptcha-with-Devise "recaptcha":https://github.com/ambethia/recaptcha Get keys: http://www.google.com/recaptcha/whyrecaptcha environment.rbrecaptcha_tags :public_key => '6Lc6BAAAAAAAAChqRbQZcn_yyyyyyyyyyyyyyyyy'Later in a controller...verify_recaptcha :private_key => '6Lc6BAAAAAAAAKN3DRm6VA_xxxxxxxxxxxxxxxxx'h2. Image upload Carrierwave http://techblog.moviepilot.com/carrierwave-as-a-replacement-for-paperclip h2. Form builder Formtastic "formtastic":https://github.com/justinfrench/formtastic "Formtastic with mongoid tutorial":https://github.com/bowsersenior/formtastic_with_mongoid_tutorial Install:$ rails g formtastic:installGenerate form for existing modelrails g formtastic:form ExistingModelName [field:type field:type] --haml --partialh2. Mongoid "Embed one with fields for":http://groups.google.com/group/mongoid/browse_thread/thread/d45d82ac6e77bd5d h2. Devise Authentication "Configure full Auth/Auth setup":http://www.tonyamoyal.com/2010/07/28/rails-authentication-with-devise-and-cancan-customizing-devise-controllers/ "Part 2":http://www.tonyamoyal.com/2010/09/29/rails-authentication-with-devise-and-cancan-part-2-restful-resources-for-administrators/ "More":http://www.michaelharrison.ws/weblog/?p=349 "Customizing Devise":http://asciicasts.com/episodes/210-customizing-devise h2. CSS with SCSS Compass (with blueprint?) "compass":https://github.com/chriseppstein/compass Lemonade (CSS Sprites) "lemonade":https://github.com/hagenburger/lemonade Textmate bundle for SCSSmkdir -p ~/Library/Application\ Support/TextMate/Bundles cd ~/Library/Application\ Support/TextMate/Bundles git clone git://github.com/kuroir/SCSS.tmbundle.git "SCSS.tmbundle" gem install nokogiri osascript -e 'tell app "TextMate" to reload bundles'"Managing Styles with Sass on Heroku":http://avandamiri.com/2010/09/15/managing-styles-with-sass-on-heroku.html "CSS Tricks (1 of 2): First, Get Down with the OOP":http://avandamiri.com/2008/09/18/css-tricks-1-of-2-first-get-down-with-the-oop.html "CSS Tricks (2 of 2): Using Rails to Manage Styles":http://avandamiri.com/2008/11/19/css-tricks-2-of-2-using-rails-to-manage-styles.html h2. Blueprint CSS framework * "Blueprint CSS":http://blueprintcss.org/ * "How to Make CSS Layouts With Blueprint, a CSS Framework ":http://www.youtube.com/watch?v=KHLrEF9tHjw * "Blueprint a closer look":http://net.tutsplus.com/tutorials/html-css-techniques/a-closer-look-at-the-blueprint-css-framework/ * "Test pages":http://www.blueprintcss.org/tests/ * "Inline forms":http://www.youtube.com/watch?v=MMY91V1m5ow&feature=player_embedded h2. Heroku "Heroku setup":http://blog.elctech.com/2009/05/17/heroku-0-to-60-in-15-minutes/ Setup Heroku for Rails 3 and ruby 1.9.2$ heroku create tiramizoo-test --stack bamboo-ree-1.9.2h2. Google Maps "IP to country geocoding":http://www.rudabet.com/blog/2010/06/ip-to-country-geocoding-in-ruby-on-rails/ "Geocoding-Users-Ip-Address-Create-User":http://efreedom.com/Question/1-1316764/Geokit-Authlogic-Geocoding-Users-Ip-Address-Create-User "geokit-rails3":https://github.com/jlecour/geokit-rails3/ - Distance calculations, for both flat and spherical environments. For example, given the location of two points on the earth, you can calculate the miles/Km between them. - IP-based location lookup utilizing hostip.info. Provide an IP address, and get city name and latitude/longitude in return - A before_filter helper to geocoder the user's location based on IP address, and retain the location in a cookie. - Geocoding from multiple providers. It provides a fail-over mechanism, in case your input fails to geocode in one service. Geocoding is provided buy the Geokit gem, which you must have installed h3. Bhm plugin <%= draw_map_of Location.new("My House", 12.345, 56.789) %> "bhm-google-maps":https://github.com/kristianmandrup/bhm-google-maps h3. API Keys * localhost:3000 - ABQIAAAAUzkItq4p7LYo2YIR_gtjpRTJQa0g3IQ9GZqIMmInSLzwtGDKaBSzEc8_FNxIfQLkpKOh9R4JB87Rig * tiramizoo-beta.heroku.com - ABQIAAAAUzkItq4p7LYo2YIR_gtjpRScPhHhTyTGueeJo8sXYsnV4VMnTBT2MqnfY3aPuvIhBjwfhTZoE2EtZA h3. Google Maps with Rails – How to "How to":http://www.developer.com/open/article.php/10930_3757576_1 Google map directions "directions":http://code.google.com/apis/maps/documentation/javascript/v2/services.html Geo auto-completion "Geo autocomplete":http://code.google.com/p/geo-autocomplete/ h3. Geocode libraries "Geocode":https://github.com/dbrady/geocodeg = Geocode.new_geocoder :google, {:google_api_key => "abcd1234_SAMPLE_GOOGLE_API_KEY_etc"} result1 = g.geocode "1600 Amphitheatre Parkway, Mountain View, CA" result2 = g.reverse_geocode "37.421759,-122.08437""Graticule":https://github.com/collectiveidea/graticule/require 'rubygems' require 'graticule' geocoder = Graticule.service(:google).new "api_key" location = geocoder.locate "61 East 9th Street, Holland, MI" p "zip: #{location.zip}"h3. Travel Modes By default, directions are assumed to be driving directions though you may request other modes of travel by passing a GTravelMode when calling the Directions.load() method. The following travel modes are supported: * G_TRAVEL_MODE_DRIVING indicates standard driving directions using the road network * G_TRAVEL_MODE_WALKING requests walking directions via pedestrian paths & sidewalks (where available.) Note: Walking directions may sometimes not include clear pedestrian paths, so walking directions are only supported if you have supplied a in the GDirections constructor; this is used to display a warning to the user in the returned turn-by-turn textual directions. If you do not have such a , a request for walking directions will return an error. h3. Handling Returned Directions If the GDirections object was constructed with a supplied GMap2 object, then the returned directions will contain a polyline overlay. If the GDirections object was constructed with a supplied element, then the returned directions will contain a GRoute object, containing a set of GStep objects. (If the directions consist of multi-point directions, the returned directions will contain multiple GRoute objects, each consisting of a series of GStep objects.) Note that the directions object is not populated with this return information immediately. For this reason, the GDirections object defines a "load" event which you can intercept to determine this state. Once directions are returned, by default, the map will display a polyline showing the route, while textual directions will display within the supplied for that purpose. The GDirections object will also internally store results which you can retrieve using GDirections.getPolyline() and/or GDirections.getRoute(i:Number) methods. Steps within a route can be retrieved using the GRoute.getStep(i:Number) method and the HTML summary of that step can be retrieved using GStep.getDescriptionHtml(). (See Routes and Steps below.) The GDirections object also fires three events which you can intercept: * "load": This event is triggered when a directions result successfully returns, but before any overlay elements are added to the map/panel. * "addoverlay": This event is triggered after the polyline and/or textual directions components are added to the map and/or DIV elements. h3. Routes and Steps The GDirections object also supports multi-point directions, which can be constructed using the GDirections.loadFromWaypoints() method. This method takes an array of textual input addresses or textual lat/lon points. Each separate waypoint is computed as a separate route and returned in a separate GRoute object, each of which contains a series of GStep objects. GRoute objects store the number of steps (of type GStep for that route, the starting and ending geocode for that route, and other computed information such as distance, duration, and exact lat/lon of the endpoint (which may be different than the ending geocode if the geocode does not lie on a road segment). Each GStep object as well contains the description for that text (e.g. "Merge onto US-101 S via the ramp to San Jose") plus computed information including the distance, duration, and exact lat/lon as well. Example: "directions simple code example":http://code.google.com/apis/maps/documentation/javascript/v2/examples/directions-simple.html h2. Copyright 2010 Tiramizoo.com
本源码包内暂不包含可直接显示的源代码文件,请下载源码包。