辅导案例-COSC2675

欢迎使用51辅导,51作业君孵化低价透明的学长辅导平台,服务保持优质,平均费用压低50%以上! 51fudao.top
Rapid Application Development COSC2675 Semester 1 2020


Tute/Lab Session (Week 2)

Welcome to RAD! In this course, you will be learning Ruby programming, Ruby on Rails framework,
MVC, TDD and many other concepts, methodologies, tools and skills widely used in industry. The key
to a successful completion of this course is practice, practice and practice!


PART 1: Ruby Syntax

1. Are the following statements syntactically correct?

a) sum = assignment +
exam

b) tax = income – threshold
* tax_rate

c) average = a + b \
2;


2. Assume we have a global variable tax_rate defined and set to 10%, define a class Car so it
supports the following use:

car1 = Car.new("Nissan", 15000)
car2 = Car.new("BMW", 45000 )
puts car1 #print=> Car model: Nissan, price: 16500
puts car2 #print=> Car model: BMW, price: 49500

car1.price= 60000;
puts car1 #print=> Car model: Nissan, price: 60000



PART 2: Setting up and simple exercises


1. This semester we will be using Docker to setup local installation of Ruby on Rails.

Make sure install the docker and docker-compose across Mac, Windows, and Linux.

https://docs.docker.com/compose/install/


Install Compose on macOS
Rapid Application Development COSC2675 Semester 1 2020


Docker Desktop for Mac and Docker Toolbox already include Compose along with other Docker apps,
so Mac users do not need to install Compose separately. Docker install instructions for these are here:
• Get Docker Desktop for Mac https://docs.docker.com/docker-for-mac/install/
• Get Docker Toolbox (for older systems) https://docs.docker.com/toolbox/overview/
Install Compose on Windows desktop systems
Docker Desktop for Windows and Docker Toolbox already include Compose along with other Docker
apps, so most Windows users do not need to install Compose separately. Docker install instructions for
these are here:
• Get Docker Desktop for Windows https://docs.docker.com/docker-for-windows/install/
• Get Docker Toolbox (for older systems) https://docs.docker.com/toolbox/overview/
If you are running the Docker daemon and client directly on Microsoft Windows Server, follow the
instructions in the Windows Server tab.
Install Compose on Linux systems
On Linux, you can download the Docker Compose binary from the Compose repository release page on
GitHub. https://github.com/docker/compose/releases
Follow the instructions from the link, which involve running the curl command in your terminal to
download the binaries. These step-by-step instructions are also included below.

Attention ! If you are running Docker on Linux, the files rails new created are owned by root. This
happens because the container runs as the root user. If this is the case, change the ownership of the new
files.

sudo chown -R $USER:$USER

This requires user to have admin access on Linux Machine.



2. Installing Ruby on Rails distribution on Docker, using the link listed for both Bitbucket and Github.

https://bitbucket.org/notalexjiang/rmit-rad-replicate/src/master/


https://github.com/pigfly/RMIT-RAD/tree/master/2020_s1/bootstrap

Rapid Application Development COSC2675 Semester 1 2020



Download the repository to your local machine and unzip the directory. Enter the directory (you may
rename the directory first) on command line environment, then use the following command to download
the rails docker image and to build

> docker-compose run web rails new . --force --no-deps --database=postgresql

> docker-compose build


Then you can check file config/database.yml which should show













Run the following commands on two separate terminals:
> docker-compose up
> docker-compose run web rake db:create

Then on your web browser, you should see your first Rails application running at this URL

http://localhost:3000

To shut it down, use this command > docker-compose down

3. Set an account with Github or Bitbucket if you don’t have one yet.

https://github.com/

https://bitbucket.org/
default: &default
adapter: postgresql
encoding: unicode
host: db
username: alex
password:
pool: 5

development:
<<: *default
database: myapp_development


test:
<<: *default
database: myapp_test

Rapid Application Development COSC2675 Semester 1 2020




4. Set an account with Heroku if you don’t one yet.

https://www.heroku.com/


5. Use your favourite code editor to explore the file directory that you created above. Some editors/IDEs
include Visual Studio Code, RubyMine, Aptana Studio, Notepad++, Sublime, Komodo and so on.


6. Try the toy app prepared by Michael Hartl.

https://www.learnenough.com/ruby-on-rails-4th-edition-tutorial/toy_app


NOTE: Michael Hartl’s tutorial uses AWS Cloud9 not Docker. The commands listed in the tutorial need
an extra “docker-compose run web” in front to run under Docker.

For example: the toy app starts with these two commands (without Docker)

> rails generate scaffold User name:string email:string
> rails db:migrate

On your machine with Docker, the commands are

> docker-compose run web rails generate scaffold User name:string email:string

> docker-compose run web rails db:migrate

Then you should see the app working at http://localhost:3000/users and
http://localhost:3000/users/new

51作业君

Email:51zuoyejun

@gmail.com

添加客服微信: abby12468