DOC PREVIEW
Penn CIT 597 - Rails

This preview shows page 1-2-15-16-17-32-33 out of 33 pages.

Save
View full document
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
View full document
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience
Premium Document
Do you want full access? Go Premium and unlock all 33 pages.
Access to all documents
Download any document
Ad free experience

Unformatted text preview:

RailsWhat is Rails?Required softwareRails philosophyThree environmentsScriptsStarting an applicationCreating an empty databaseThe directories, IThe directories, IIThe app subdirectoryNaming conventions in Ruby“Convention over configuration”Model-View-Controller (MVC)Naming conventions in Rails, INaming conventions in Rails, IITypical flow of controlScaffoldingThe browser callThe controllerThe modelSome useful validationsThe view(s)Components of a viewConstructing a viewMethods useful in the viewWhere methods come fromAdding tables to the databaseStarting migrationsModifying the databaseMethods to use in up and downStatusThe EndJan 14, 2019RailsWhat 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 technologiesRequired 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 databaseRails 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 testingThree 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 speedScriptsA lot of work is done in the Rails world by generate and rake scriptsThe generate scripts are called like this:ruby script\generate generator options argsGenerators typically create files and directories for youSome built-in generators are: controller, model, scaffold, mailer, and web_serviceThe rake (like UNIX make) scripts are called like this:rake name:name:nameRake scripts are typically used to propagate changes by updating files that depend on other filesRake scripts are written in RubyStarting an applicationTo create a new application, say, “MyApplication”, enter the command: rails MyApplicationThis creates a directory (folder) named MyApplication and, beneath it, a large directory structure and a number of filesCreating an empty databaseThe following instructions are for MySQL on Windows, as configured in InstantRails1. At the command line, enter mysql -u root –pand just hit Enter when prompted for a password2. Type the following lines into MySQL: create database MyApp_development; grant all on MyApp_development.* to 'ODBC'@'localhost'; •The above creates the development database for an application named MyApp; you can repeat these two lines to create the test and production databases, if you like3. Type exitThe directories, IRails creates the following subdirectories of the MyApplication 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 applicationsThe 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 directoriesThe app subdirectoryThe app/ subdirectory containsThe controllers/ subdirectory, which containsThe application.rb fileA table_controller.rb file for each table in your applicationThe helpers/ subdirectory, which containsThe application_helper.rb fileA table_helper.rb file for each table in your applicationThe models/ subdirectory, which containsA table.rb file for each table in your applicationThe views/ subdirectory, which containsThe index.rhtml fileaction.rhtml files for most of the methods in your controllersNaming conventions in RubyRuby requires the following naming conventions:The names of classes, modules, and constants must begin with a capital letterThe names of variables and methods must begin with a lowercase letterRuby encourages the following naming conventions:The names of classes, modules, and constants should be written in CamelCase; for example, ActiveRecordThe names of variables and methods should be written in all lowercase, with underscores between words; for example, chunky_baconFile names in Ruby follow the same rules as variable and function names; for example, my_application.rb“Convention over configuration”In other web application frameworks, you need many configuration files to specify how the various parts of your application fit togetherRails assumes you have named things in a certain way, then finds the parts and fits them together itselfRails uses both capitalization and pluralization rulesModel-View-Controller (MVC)Rails uses the MVC design patternIn


View Full Document

Penn CIT 597 - Rails

Documents in this Course
DOM

DOM

21 pages

More DOM

More DOM

11 pages

DOM

DOM

21 pages

RELAX NG

RELAX NG

31 pages

RELAX NG

RELAX NG

31 pages

RELAX NG

RELAX NG

31 pages

RELAX NG

RELAX NG

31 pages

Rake

Rake

12 pages

Ruby

Ruby

58 pages

DOM

DOM

21 pages

Tomcat

Tomcat

16 pages

DOM

DOM

21 pages

Servlets

Servlets

29 pages

Logging

Logging

17 pages

Html

Html

27 pages

DOM

DOM

22 pages

RELAX NG

RELAX NG

30 pages

Servlets

Servlets

28 pages

XHTML

XHTML

13 pages

DOM

DOM

21 pages

DOM

DOM

21 pages

Servlets

Servlets

26 pages

More CSS

More CSS

18 pages

Servlets

Servlets

29 pages

Logging

Logging

17 pages

Load more
Download Rails
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Rails and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Rails 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?