Ruby on rails This ppt contains a pot pourri of information including some sql, some php, some instant rails and so on.

Slides:



Advertisements
Similar presentations
JQuery MessageBoard. Lets use jQuery and AJAX in combination with a database to update and retrieve information without refreshing the page. Here we will.
Advertisements

Copyright © 2008 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 15 Introduction to Rails.
The Librarian Web Page Carol Wolf CS396X. Create new controller  To create a new controller that can manage more than just books, type ruby script/generate.
PRACTICAL PHP AND MYSQL WALKTHROUGH USING SAMPLE CODES – MAX NG.
Chapter 15 © 2010 by Addison Wesley Longman, Inc Origins and Uses of Ruby - Designed by Yukihiro Matsumoto; released in Use spread rapidly.
Methods for Rails. File Structures This is taken directly from app Holds all the code that's specific.
27-Jun-15 Rails. What is Rails? Rails is a framework for building web applications This involves: Getting information from the user (client), using HTML.
Intermediate PHP & MySQL
A Guide to MySQL 3. 2 Objectives Start MySQL and learn how to use the MySQL Reference Manual Create a database Change (activate) a database Create tables.
A complete ror application. Some easy tutorials This uses oracle but it is easy to replace that with mysql:
Creating a wiki blog. Run apps that come with instant rails distribution select I /rails applications/open ruby console window Cd to cookbook or typo.
Ruby on Rails Creating a Rails Application Carol E Wolf CS396X.
Dynamic Web site With PHP and MySQL. MySQL The combination of MySQL database and PHP scripting language is optimum for building dynamic websites. MySQL.
1 CS428 Web Engineering Lecture 23 MySQL Basics (PHP - VI)
Drupal Workshop Introduction to Drupal Part 1: Web Content Management, Advantages/Disadvantages of Drupal, Drupal terminology, Drupal technology, directories.
Ruby on Rails: An Introduction JA-SIG Summer Conference 2007 Michael Irion The University of Tulsa.
PHP Programming. Topics Background and History of PHP Installation Comments in PHP Variables Conditions Loops Functions File Handling Database Handling.
Ruby on Rails. What is Ruby on Rails? Ruby on Rails is an open source full-stack web framework. It is an alternative to PHP/MySQL. It can render templates,
Rails and Grails. To get started Make sure you have java installed You can get the sdk and jre at:
Reading Data in Web Pages tMyn1 Reading Data in Web Pages A very common application of PHP is to have an HTML form gather information from a website's.
© Yanbu University College YANBU UNIVERSITY COLLEGE Management Science Department © Yanbu University College Module 6:WEB SERVER AND SERVER SIDE SCRPTING,
INFM 603: Information Technology and Organizational Context Jimmy Lin The iSchool University of Maryland Thursday, October 18, 2012 Session 7: PHP.
A Guide to SQL, Eighth Edition Chapter Three Creating Tables.
UC Berkeley Hello Rails. Review: MVC Goal: separate organization of data (model) from UI & presentation (view) by introducing controller –mediates user.
Session 5: Working with MySQL iNET Academy Open Source Web Development.
Server-side Scripting Powering the webs favourite services.
Tutorial 10 Adding Spry Elements and Database Functionality Dreamweaver CS3 Tutorial 101.
1 PHP and MySQL. 2 Topics  Querying Data with PHP  User-Driven Querying  Writing Data with PHP and MySQL PHP and MySQL.
Mark Dixon Page 1 23 – Web applications: Writing data to Databases using PhP.
© 2003 By Default! A Free sample background from Slide 1 Week 2  Free PHP Hosting Setup  PHP Backend  Backend Security 
FUNCTIONS AND STORED PROCEDURES & FUNCTIONS AND PROTECTING A DB AND PHP (Chapters 9, 15, 18)
MVC & ActiveRecord by Christian Mohr & Mohamed Souiai.
PHP meets MySQL.
1 Data Bound Controls II Chapter Objectives You will be able to Use a Data Source control to get data from a SQL database and make it available.
Instructors begin using McGraw-Hill’s Homework Manager by creating a unique class Web site in the system. The Class Homepage becomes the entry point for.
15/10/20151 PHP & MySQL 'Slide materials are based on W3Schools PHP tutorial, 'PHP website 'MySQL website.
Introduction to MySQL Lab no. 10 Advance Database Management System.
Installing and Using MySQL and phpMyAdmin. Last Time... Installing Apache server Installing PHP Running basic PHP scripts on the server Not necessary.
PHP MySQL Introduction. MySQL is the most popular open-source database system. What is MySQL? MySQL is a database. The data in MySQL is stored in database.
School of Computing and Information Systems CS 371 Web Application Programming PHP – Forms, Cookies, Sessions and Database.
Week 7. Lecture 2 Functions, Arrays, PHP&MySQL. Function with More than one argument and a return statement For a function to return a value, the return.
CAKEPHP Blog tutorial. what you’ll need examples/blog/blog.html 2  A running web server  A database server.
PHP MySQL Image Gallery. The admin section contain the following : Add New Album Album List Edit & Delete Album Add Image Image List Edit & Delete Image.
Unit 5, Lesson 1 Working with Databases. Objectives Identify the parts of the Access screen. Identify the parts of the Access screen. Understand the purpose.
1 Session 1: Introduction to PHP & MySQL iNET Academy Open Source Web Development.
Rails & Ajax Module 5. Introduction to Rails Overview of Rails Rails is Ruby based “A development framework for Web-based applications” Rails uses the.
PHP on a Fast Track a quick introduction to PHP programming by Jarek Francik last time updated in 2012.
Creating a simple database This shows you how to set up a database using PHPMyAdmin (installed with WAMP)
Ruby on Rails+MySQL. Sebesta corvette example In rails_apps create a directory (car_app), change to this dir and run rails (rails cars) Rails_apps Car_app.
WAMP Server Installatin Shiyun Wen. WAMP Server Installation  WAMP Server is an integrated installation of Apache, MySQL, and PHP for Windows. Following.
Unit 1 – Web Concepts Instructor: Brent Presley.
1 Dr Alexiei Dingli Web Science Stream Installing ROR.
CSC 405: Web Application Engineering II8.1 Web programming using PHP What have we learnt? What have we learnt? Underlying technologies of database supported.
IS2803 Developing Multimedia Applications for Business (Part 2) Lecture 2: Introduction to IS2803 Rob Gleasure
Ruby on Rails. Web Framework for Ruby Designed to make it easier to develop, deploy, and maintain web applications Design with Model-View-Controller –almost.
Visual Database Creation with MySQL Workbench 도시정보시스템 설계
Introduction to MySQL  Working with MySQL and MySQL Workbench.
1.Switch on the computer and wait for loading. 2.Select the Windows 7 OS at the end of the list. 3.Click on the link ‘Administrator’ 4.Enter the administrator.
Installing and Configuring Moodle. Download Download latest Windows Install package from Moodle.orgMoodle.org.
1.Switch on the computer and wait for loading. 2.Select the Windows 7 OS at the end of the list. 3.Click on the link ‘Administrator’ 4.Enter the administrator.
COM621: Advanced Interactive Web Development Lecture 10 PHP and MySQL.
Migrating Wordpress Migrating Wordpress can sometimes get more complicated as it should. There is no plugin that does this for you, the best way is to.
3 A Guide to MySQL.
Storing Images Connect to the server using the correct username and password. $conn = mysql_connect(“yourserver”, “joeuser”, “yourpass”); Create the database.
Web Browser server client 3-Tier Architecture Apache web server PHP
Chapter 15 Introduction to Rails.
Tutorial 6 PHP & MySQL Li Xu
Install MySQL Community Server and MySQL Workbench
Presentation transcript:

Ruby on rails This ppt contains a pot pourri of information including some sql, some php, some instant rails and so on

Where to get rails Ruby, gems, and rails can be downloaded separately, from a variety of sources, in particular RubyForge. I downloaded ruby to my desktop so I could conveniently develop applications I downloaded the “Instant Rails” distribution which comes with Ruby, PHP, and MySQL and the Apache server from This simply gets unzipped. Use 7-zip rather than winzip. When you run it, you get an interface to start/stop the apache and mysql servers. Not detailed here –you may separately need to install ruby gems – the ruby package manager. It is available from rubyforge.org.. After extraction, run prompt>ruby setup.rb

bookmarks Among those you may want to mark are tha rails api pages: The Railspace book has a site at

Instant Rails looks like this:The I in lefthand corner is clicked to open menus

Alternatively For windows, download Ruby (windows installer) at RubyForge.org Install RubyGems (a zip file at RubyForge) After extraction, run prompt>ruby setup.rb Install Rails from the commandline prompt>gem install rails –include dependencies

Remarks on rails Rails is written in and for ruby. Rails is a net programming framework, that builds various directories and files common to an MVC architecture. You modify and add to these to customize your development. Text walkthrough seems mostly accurate. I’ve make some screen shots/notes/etc.

mvc browser controller model database view

A convention For a site named MySite, the project would be created with lowercase and underscore, as my_site. You build a subdirectory below rails_apps and run rails from there.

Directories: where do things go? app: views, models, helpers, controllers test: unit, integration,functional, fixtures public: stylesheets, javascripts, images lib: tasks db: migrate config: environments

Run mongrel: ruby script/server from rails1 directory

Mongrel at port 3000

Converting a ruby application to a rails application

Summary of steps Add a directory under rail_apps (I called mine pfix) and change to this directory: Mkdir pfix Cd pfix Then run rails in this directory to create files and folders using a new subdirectory name, like postfix. I used the_form.rhtml and result.rhtml files for the view. Evalcontroller is basically the postfix program. The stack class needs to be put in this controller directory as well. I added a variable in the and a method errors in the stack class which a field value, to the evalcontroller. The original line, the answer and any error appear in the result form.

After clicking evaluate postfix button

An expression with errors

Notes Evalcontroller is in this slide’s notes Stack class changes left as exercise

The_form for postfix <!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.1//EN" " --> Postfix Form Welcome to postfix evaluator Enter postfix expression:

Result.rhtml <!DOCTYPE html PUBLIC "-//w3c//DTD XHTML 1.1//EN" " <!-- result.rhtml - result view for the postfix application --> result.rhtml postfix expression: Evaluated: any errors:

On the DOS window where mongrel is running… Processing EvalController#the_form (for at :25:10) [GET] Session ID: a97b5ba b6dc d8909c3 Parameters: {"action"=>"the_form", "controller"=>"eval"} Rendering eval/the_form Completed in (10000 reqs/sec) | Rendering: (0%) | 200 OK [ /localhost/eval/the_form] form] Processing EvalController#result (for at :25:39) [POST] Session ID: a97b5ba b6dc d8909c3 Parameters: {"action"=>"result", "expression"=>" * + 70 /", "controlle r"=>"eval"} Rendering eval/result Completed in (10000 reqs/sec) | Rendering: (0%) | 200 OK [ /localhost/eval/result] esult]

Access to phpMyAdmin Click the I Select configure Select database

phpMyAdmin in instantrails: go to configure/database from I menu

Unrelated to ruby: accessing mysql from php in instantrails distribution of mysql <?php // Make a MySQL Connection mysql_connect("localhost", "root", "") or die(mysql_error()); mysql_select_db("test") or die(mysql_error()); // Retrieve all the data from the "example" table $result = mysql_query("SELECT * FROM Students") or die(mysql_error()); // store the record of the "example" table into $row //$row = mysql_fetch_array( $result ); // Print out the contents of the entry //$result = mysql_query($query) or die(mysql_error()); while($row = mysql_fetch_array($result)){ echo $row['name']. " - ". $row['id']; echo " "; } ?>

Note url…put php files in www directory

RadRails Radrails is a 43 mb download from SourceForge It is a rails IDE

Radrails looks like this – I wound up not using this environment

Generating controller for rail_space C:\InstantRails\rails_apps\RailSpace\rail_space>ruby script/generate controller site index about help exists app/controllers/ exists app/helpers/ create app/views/site exists test/functional/ create app/controllers/site_controller.rb create test/functional/site_controller_test.rb create app/helpers/site_helper.rb create app/views/site/index.rhtml create app/views/site/about.rhtml create app/views/site/help.rhtml C:\InstantRails\rails_apps\RailSpace\rail_space>

Site files Note the app/views/site (index, about, help) rhtml files are generated automatically and correspond to (next slide) methods of site controller

Site_Controller.rb class SiteController < ApplicationController def index end def about end def help end

A login generator Some notes for a prewritten login generator for rails are at Generatorhttp://wiki.rubyonrails.org/rails/pages/Login Generator

Notes on setting up login Edit app/controllers/application.rb require 'login_system' class ApplicationController < ActionController::Base include LoginSystem model :user end Edit app/controllers/account_controller.rb to set who if anyone can delete users. Until they have admin roles, most people can set it so only account holders can delete their account: def delete if params['id'] == params['id'] Edit your own controllers now, and add the line before_filter :login_required to the inside of the class so that it ends up looking something like this: class AllMySecretsController < ApplicationController before_filter :login_required def show_one_secret... end Of course, I sometimes don’t want every method hidden behind the iron curtain, so I can exclude some of them (such as show_one_secret above) from being protected like so: class AllMySecretsController < ApplicationController before_filter :login_ required, :except => [ :show_one_secret ] def show_one_secret... end

Installing some gems – just the last is needed for this login generator C:\InstantRails\ruby>gem install --source localization _generator Bulk updating Gem source index for: Successfully installed rake Successfully installed localization_generator gems installed Installing ri documentation for rake Installing RDoc documentation for rake C:\InstantRails\ruby>gem install --source salted_login _generator Successfully installed salted_login_generator gem installed C:\InstantRails\ruby>gem install --source login_genera tor Successfully installed login_generator gem installed C:\InstantRails\ruby>

The login generator C:\InstantRails\rails_apps>mkdir loginapp C:\InstantRails\rails_apps>cd loginapp C:\InstantRails\rails_apps\loginapp>rails MyLogin create create app/controllers create app/helpers create app/models create app/views/layouts … C:\InstantRails\rails_apps\loginapp\MyLogin>gem install login_generator Bulk updating Gem source index for: Successfully installed login_generator C:\InstantRails\rails_apps\loginapp\MyLogin>ruby script/generate login Acco create lib/login_system.rb create app/controllers/account_controller.rb create test/functional/account_controller_test.rb create app/helpers/account_helper.rb create app/models/user.rb create test/unit/user_test.rb create test/fixtures/users.yml create app/views/layouts/scaffold.rhtml create public/stylesheets/scaffold.css create app/views/account create app/views/account/welcome.rhtml create app/views/account/login.rhtml create app/views/account/logout.rhtml create app/views/account/signup.rhtml create README_LOGIN C:\InstantRails\rails_apps\loginapp\MyLogin>

Be sure to create the correct database for this app Rails uses test, production and development databases for each app. Here use the database mylogin_development Create the table users (see next slide) replace mylogin by your app name

Create a user table in mysql here’s a script you can run in phpmyadmin: CREATE TABLE users ( id int(11) NOT NULL auto_increment, login varchar(80) default NULL, password varchar(40) default NULL, PRIMARY KEY (id) );

Running this app

MrEd with pw horse

Then you get this (there’s some work to do still to arrange redirection)