Presentation is loading. Please wait.

Presentation is loading. Please wait.

A complete ror application. Some easy tutorials This uses oracle but it is easy to replace that with mysql:

Similar presentations


Presentation on theme: "A complete ror application. Some easy tutorials This uses oracle but it is easy to replace that with mysql:"— Presentation transcript:

1 A complete ror application

2 Some easy tutorials This uses oracle but it is easy to replace that with mysql: http://www.oracle.com/technology/pub/articles/haefel- oracle-ruby.html http://www.oracle.com/technology/pub/articles/haefel- oracle-ruby.html There are many rails tutorials online… This one builds the cookbook part 1… and you actually write some code: http://ebooks.smartweb.co.th/Ruby%20On%20Rails%20E- Books/ONLamp.com%20- %20Rolling%20with%20Ruby%20on%20Rails%20- %20Part%201%20(January%202005).pdf And this is part two of the cookbook: http://www.onlamp.com/pub/a/onlamp/2005/03/03/rails.html

3 Create comics app Use I/…/ to open ruby console window. Fromrails apps run: C:\InstantRails\rails_apps>rails comics_catalog create create app/controllers create app/helpers create app/models create app/views/layouts create config/environments create config/initializers create db create doc create lib create lib/tasks create log create public/images create public/javascripts create public/stylesheets create script/performance create script/process …MANY MORE create public/javascripts/dragdrop.js create public/javascripts/controls.js create public/javascripts/application.js create doc/README_FOR_APP create log/server.log create log/production.log create log/development.log create log/test.log C:\InstantRails\rails_apps> Then change to comics_catalog: C:\InstantRails\rails_apps>cd comics_catalog C:\InstantRails\rails_apps\comics_catalog>

4 Problems with Sql lite???? My brandnew version of instantrails (4/09) seems to not have sqllite but it seemed to want it. You can get sqllite at http://www.sqlite.org/download.html This site describes installation for sqllite in ruby/rails: http://accidentaltechnologist.com/ruby/ruby-on-rails/setting-up- sqlite3-for-ruby-on-rails-development/ http://accidentaltechnologist.com/ruby/ruby-on-rails/setting-up- sqlite3-for-ruby-on-rails-development/ He says to copy sqllite.exe into ruby/bin, and to run the gem command below. I got an error missing a dll which I downloaded from http://www.dll- files.com/dllindex/pop.php?sqlite3http://www.dll- files.com/dllindex/pop.php?sqlite3 Not sure if you’ll need it.. Then you need to add it to your path settings, which you are not likely to be able to do!!! Then you still need to install the associated gem: On command line in ruby/bin: –gem install sqlite3-ruby

5 Contents of comics_catalog and config dir within comics

6 Databases This app will use a database to hold comics data. Actually, separate dbs for development, testing and productions are often used. You can create these using phpmyadmin or from within the rails environment by running a rails command: rake The next slide shows how to create databases needed for testing, production and development. Save the contents in appdir/config/database.yml There will be a defaulted database.yml in there already. If you have mysqllite then your file will look like the following slide.

7 Create config/database.yml development: adapter: mysql database: comics_catalog_development username: root password: host:localhost # Warning: The database defined as "test" will be erased and # re-generated from your development database when you run "rake". # Do not set this db to the same as development or production. test: adapter: mysql database: comics_catalog_test username: root password: host:localhost production: adapter: mysql database: comics_catalog_production username:root password: host:localhost

8 Sqllite database.yml development: adapter: sqlite3 database: db/development.sqlite3 timeout: 5000 # Warning: The database defined as 'test' will be erased and # re-generated from your development database when you run 'rake'. # Do not set this db to the same as development or production. test: adapter: sqlite3 database: db/test.sqlite3 timeout: 5000 production: adapter: sqlite3 database: db/production.sqlite3 timeout: 5000

9 Run scaffolding script to create columns for (future) tables… notice it creates db/migrate file C:\InstantRails\rails_apps\comics_catalog>ruby script/generate scaffold comic ti tle:string issue:integer publisher:string :0:Warning: Gem::SourceIndex#search support for Regexp patterns is deprecated exists app/models/ exists app/controllers/ exists app/helpers/ create app/views/comics exists app/views/layouts/ exists test/functional/ exists test/unit/ create app/views/comics/index.html.erb create app/views/comics/show.html.erb create app/views/comics/new.html.erb create app/views/comics/edit.html.erb create app/views/layouts/comics.html.erb create public/stylesheets/scaffold.css dependency model :0:Warning: Gem::SourceIndex#search support for Regexp patterns is deprecated exists app/models/ exists test/unit/ exists test/fixtures/ create app/models/comic.rb create test/unit/comic_test.rb create test/fixtures/comics.yml create db/migrate create db/migrate/001_create_comics.rb create app/controllers/comics_controller.rb create test/functional/comics_controller_test.rb create app/helpers/comics_helper.rb route map.resources :comics C:\InstantRails\rails_apps\comics_catalog>

10 Run rake to create dbs C:\InstantRails\rails_apps\comics_catalog>rake db:migrate --trace (in C:/InstantRails/rails_apps/comics_catalog) ** Invoke db:migrate (first_time) ** Invoke environment (first_time) ** Execute environment ** Execute db:migrate == 1 CreateComics: migrating ================================================== -- create_table(:comics) -> 0.1090s == 1 CreateComics: migrated (0.1090s) ========================================= ** Invoke db:schema:dump (first_time) ** Invoke environment ** Execute db:schema:dump C:\InstantRails\rails_apps\comics_catalog>

11 Believe it or not… We’ve created our comics site. There are two servers that come with RoR. We need to start a server. To check out our site run: ruby script/server C:\InstantRails\rails_apps\comics_catalog>ruby script/server => Booting Mongrel (use 'script/server webrick' to force WEBrick) => Rails application starting on http://0.0.0.0:3000 => Call with -d to detach => Ctrl-C to shutdown server ** Starting Mongrel listening at 0.0.0.0:3000 ** Starting Rails with development environment...

12 Localhost:3000/comics opens the scaffolded CRUD functionality page

13 Creating comics


Download ppt "A complete ror application. Some easy tutorials This uses oracle but it is easy to replace that with mysql:"

Similar presentations


Ads by Google