Download presentation
Presentation is loading. Please wait.
1
27-Jun-15 Rails
2
What is Rails? Rails is a framework for building web applications This involves: Getting information from the user (client), using HTML forms Doing validation Maintaining session information Managing a database Displaying results to the user Rails differs from similar frameworks in C++ or Java Rails applications can be built much more quickly Rails requires knowledge of fewer technologies
3
Required software You need: The Ruby language A database, such as MySQL A Ruby-capable web server, such as lightppd, WEBRick, or Mongrel On Windows, InstantRails provides all of these On Macintosh, Locomotive provides these On Linux you probably have to assemble the pieces yourself It’s also helpful to have: A good text editor, such as TextMate or TextPad A Ruby IDE, such as Eclipse with the RDT plugin, or RadRails A GUI interface for looking at your database
4
Rails philosophy Convention over configuration Other frameworks use several XML configuration files to specify where everything is, and how the parts are related Rails assumes a standard configuration. Don't Repeat Yourself (DRY) Every piece of information (program or data) should be represented once and only once Rails provides a structure that encourages DRY Agile development In Rails we start with a working program and “grow” it by making small changes In Rails it is easy to re-test after every small change Rails provides strong support for unit testing
5
Three environments By default, Rails projects use three environments The development environment Classes are reloaded after every change, so every change you make happens “immediately”--you don’t have to restart the server This is where you do most of your work The test environment Classes are also reloaded after every change For each test, Rails creates a fresh copy of the data in the test database The production environment Classes are only loaded once Changes typically require stopping and restarting the server The environment is tuned for speed
6
Starting an application To create a new application, such as the Cookbook application in the Curt Hibbs example, enter the command: rails cookbook This creates a directory (folder) named cookbook and, beneath it, a large directory structure and a number of files
7
The directories, I Rails creates the following subdirectories of the cookbook directory: app -- more about this directory later components -- reusable components config -- configuration information, including database connection parameters db -- database schema information doc -- autogenerated documentation lib -- code produced by your company and shared by many applications vendor -- purchased code shared by many applications
8
The directories, II More subdirectories log -- log files produced by the application public -- the web-accessible directory; your program appears to be running from here Rakefile -- scripts for creating documentation and tests script -- utility scripts tests -- unit tests, functional tests, mocks, and fixtures Of these, the app subdirectory is the most important, but you will probably also use the config, db, and test directories
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.