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 cars
Go to cars dir and type: ruby script/generate controller main C:\InstantRails\rails_apps>mkdir car_app C:\InstantRails\rails_apps>cd car_app C:\InstantRails\rails_apps\car_app>rails cars create create app/controllers create app/helpers create app/models create app/views/layouts create config/environments create components create db create doc create lib create lib/tasks … C:\InstantRails\rails_apps\car_app>cd cars C:\InstantRails\rails_apps\car_app\cars>ruby script/generate controller main exists app/controllers/ exists app/helpers/ create app/views/main exists test/functional/ create app/controllers/main_controller.rb create test/functional/main_controller_test.rb create app/helpers/main_helper.rb C:\InstantRails\rails_apps\car_app\cars>
Building tables I used phpmyadmin to build the tables. The text uses scripts in mysql to generate the tables.
main/welcome
Requesting all coupes from 1970 to 2005
Source files for cars app (with little guidance on where to put them)
Where to put the files Put controllers in controllers Put rhtml (or directories with display.rhtml) in views Models dir
controllers
views
Create a new database, cars_development
Phpmyadmin from rails
Looking at a table
An app dir in a rails application
Trying to register to be a member returns “user created” if no errors
User “secretariat” created
Secretariat in db
So what all is in this app?
application.rb # Filters added to this controller apply to all controllers in the application. # Likewise, all the methods added will be available for all controllers. class ApplicationController < ActionController::Base # Pick a unique cookie name to distinguish our session data from others' session :session_key => '_rail_space_session_id' end
site_controller class SiteController < ApplicationController def to 'My' RailSpace!" end def 'My' RailSpace!" end def for 'My' RailSpace!" end
user_controller class UserController < ApplicationController def index end def = "Register" if = User.new(params[:user]) render :text => "User created!" end
app/models- users.rb in notes
App/views/user
register.rhtml Register Enter Your Details Screen name: <%= form.text_field :screen_name, :size => User::SCREEN_NAME_SIZE, :maxlength => User::SCREEN_NAME_MAX_LENGTH %> <%= form.text_field : , :size => User:: _SIZE, :maxlength => User:: _MAX_LENGTH %> Password: <%= form.password_field :password, :size => User::PASSWORD_SIZE, :maxlength => User::PASSWORD_MAX_LENGTH %> "submit" %>
login.rhtml Log in Enter Your Details Screen name: <%= form.text_field :screen_name, :size => User::SCREEN_NAME_SIZE, :maxlength => User::SCREEN_NAME_MAX_LENGTH %> Password: <%= form.password_field :password, :size => User::PASSWORD_SIZE, :maxlength => User::PASSWORD_MAX_LENGTH %> "submit" %> Not a member? "register" %>
Now…logging in
And then…