Getting Started with myExperiment, for Developers
Note: this page is outdated.
By Sergejs Aleksejevs, 6th October 2008 / Last updated 17th February 2009
- 1 Getting Started with myExperiment, for Developers
- 1.1 Preparation
- 1.2 Getting Familiar with the Codebase
- 1.2.1 Model / View / Control :: the idea & relevant folders where these reside:
- 1.2.2 How these MVC components (+Helpers) interact together:
- 1.2.3 What are the rest of folders meant for:
- 1.2.4 Routes in Rails
- 1.2.5 Config files (environment_private.yml & database.yml)
- 1.2.6 Where and in Which Order to Search Through Documentation and Codebase for Unknown Methods
- 1.2.7 Difference between 'render' and 'redirect_to'
Note: this page is outdated.
Setting up the development environment
- Software installation (Eclipse, RadRails, Instant Rails, mySQL, phpMyAdmin, SVN, <something else?> )
1) Ruby on Rails * InstantRails (Windows only -- http://instantrails.rubyforge.org/wiki/wiki.pl) (then add this to PATH environment variable: C:\InstantRails\ruby\bin;C:\InstantRails\php;C:\InstantRails\mysql\bin) - it is likely that a message box saying "Either Apache of MySQL cannot run because another program is using it's port" will appear; this can be caused by Skype (which then needs to be switched off or switched to 'offline' mode prior to starting InstantRails) or IIS Service (which needs to be stopped - also prior to launching InstantRails); * Locomotive (MacOS 10.4 Tiger -- http://sourceforge.net/projects/locomotive) * Not required (MacOS 10.5 Leopard and above, as Ruby Rails already included into the installation within develoment tools) * RubyWorks (Ubuntu -- http://studios.thoughtworks.com/rubyworks/download-ruby-production-stack) * FiveRuns (Linux / MacOS -- http://www.fiveruns.com/products/rm/install) * For more info on installing Ruby on Rails on different OSs, see: http://wiki.rubyonrails.org/rails/pages/ (scroll down to the pages starting with "RailsOn<whatever_OS_you_run>") 2) Eclipse (http://www.eclipse.org/downloads/) -- Window -> Preferences -> General -> Capabilities -> Switch on "Classic Update" 3) Git for Eclipse (built in) myExperiment repository is located at: https://github.com/myExperiment/myExperiment.git 4) Aptana Studio Plugin for Eclipse (http://www.aptana.com/docs/index.php/Plugging_Aptana_into_an_existing_Eclipse_configuration) -- AptanaStudio (http://update.aptana.com/install/studio/3.2/) 5) RadRails Plugin for Eclipse -- RadRails (http://update.aptana.com/install/rails/3.2/) -- point Eclipse to the correct Ruby Interpreter folder: Eclipse -> Window -> Preferences -> Ruby -> Installed Interpreters
- For commits, either send Github pull requests or ask to become a myExperiment team member on GitHub.
- Checking out latest trunk
- Setting up servers in Eclipse
- Copying & updating config files (\config\environment_private.rb, \config\database.yml, \config\captcha.yml)
- Launching Mongrel server in Eclipse for myExperiment project
- Launching web-browser to check if everything's working
- http://www.myexperiment.org/ :: Main Site
- http://wiki.myexperiment.org/ :: Project Wiki
- http://www.myexperiment.org/feedback :: Feedback form on myExperiment
- http://bugs.myexperiment.org/ :: FogBugz, bug tracking software
- http://www.eclipse.org/ :: Eclipse, an open-source IDE
- http://www.eclipse.org/subversive/documentation/teamSupport/repos_persp.php :: SVN Repository Perspective in Eclipse
- http://www.aptana.com/rails :: RadRails, Eclipse plug-in for Ruby-on-Rails web-development
- http://instantrails.rubyforge.org/wiki/wiki.pl :: "Instant Rails is a one-stop Rails runtime solution containing Ruby, Rails, Apache, and MySQL, all pre-configured and ready to run."
- http://tortoisesvn.tigris.org/ :: "TortoiseSVN is a really easy to use Revision control / version control / source control software for Windows."
- http://books.google.co.uk/books?id=a8vXdlNNBuQC&pg=PA5&lpg=PA5&dq=instant+rails+macos&source=web&ots=WUr5vQFize&sig=_jZ6-ypneP6lNco7C490DeEr7to&hl=en&sa=X&oi=book_result&resnum=3&ct=result#PPP1,M1 :: "Practical Rails Projects" book
- http://www.gotapi.com/rubyrails :: Ruby / Rails Documentation
- http://www.w3schools.com/css/css_reference.asp :: W3Schools CSS Documentation
- http://developer.yahoo.com/yui/fonts/ :: YUI Fonts
Getting Familiar with the Codebase
Model / View / Control :: the idea & relevant folders where these reside:
- for support of the business rules;
- keeping the data structure;
- and interactions with DB;
- (names of Models are related to names of tables in the DB: all Models by convention should have their names in singular form; for each model that needs to perform data management and interaction with the DB, there exists a corresponding table in the DB, that has a plural form of the name of the related Model as its name).
- Views are to be kept as simple and clear as possible;
- Possible to achieve dynamic content display with in-line Ruby, by enclosing Ruby statements within <% %> and <%= -%>.
- methods in the Controllers are used to invoke Views and talk to Models;
- default action for each Controller is 'index', when other is not specified.
How these MVC components (+Helpers) interact together:
- Model can be accessed from everywhere;
- instance variables from Models are available in the Controllers through <object_name>.<variable_name> (following the principles of object orientation);
- instance variables from the Controllers are available in the Views;
- methods from Helpers are available just in the Views;
What are the rest of folders meant for:
- \lib\ - modules that are created by myExperiment team for re-use in multiple places around the code;
- \vendor\plugins\ - modules that are available for reuse, which may / may not be customised (but not written entirely) by us;
- \public\ - index page (not served by Rails) and stylesheets;
- \config\ - all the important configuration files;
- \db\migrate\ - DB migration files;
Routes in Rails
- RESTful routes (Create, Read, Update, Delete actions)
- named routes
- available only in the Views and Controllers
- difference between "user_path(<user_id>)" and "user_url(<_user_id>)": the former produces a partial path to the required resouce (/users/<user_id>), the latter does the same, but prepends the base URI to its output;
- difference between 'map.resources' & 'map.connect': the former is used to create all RESTful routes for the resource, but the latter attaches just one defined action for that resource and won't allow named routes to work;
- attaching actions to :collection and :member in map.resources
- structure of a route with an action attached to the object:
+++++++++++++++++ %%%%% $$$$
(pluses standing for action name within controller, percent signs for controller name, dollar signs for choice between 'path' and 'url')
- nested routes
- created with two IDs: "membership_path(<user_id>, <membership_id>)" or "membership_url(<user_id>, <membership_id>)"
Config files (environment_private.yml & database.yml)
- environment_private.yml - used to declare constants universally accessible around the application; also mailing settings.
- database.yml - used for defining which databases to uses in different modes (development/production/testing) and how to connect to them;
Where and in Which Order to Search Through Documentation and Codebase for Unknown Methods
- GotAPI (or any other Ruby documentation);
- \helpers\application_helper.rb - for methods in any of the Views;
- \controllers\application.rb - for methods in any of the Controllers or Views;
- \lib - for our own reusable libraries;
- \vendor\plugins - for the external libraries that we make use of.
Difference between 'render' and 'redirect_to'
- 'render' preserves the parameter hash and loads the desired page (just as a standard way of sending response to the users browser after processing some action);
- 'redirect_to' erases anything that tied the previous page to some state (i.e. clears flash[:error/notice] object, erases all parameters in the hash, etc) and loads the desired page from scratch.
- good explanation of this can be found here (see last comment at the end of the page): http://www.rubyonrailsexamples.com/rails-tips/rails-render/