http://www.sw.it.aoyama.ac.jp/2019/Projects2/lecture7.html
© 2019 Martin J. Dürst 青山学院大学
6b_wrestler_table.html.erb
that outputs a table of wrestlers from the database.webrick and test your Web page while you develop
it.sort=stable,
sort=division, sort=weight,
sort=height) to be able to select the sort order.<a href='?sort=weight'>Sort by weight</a>)sort method as in exercise
5c, but use the ActiveRecord order method.limit
method.6b_wrestler_table.html.erb to Moodle
(deadline: May 22 (Wednesday), 19:00).Problem: Many different parts of processing are mixed up. This may work for such a small example, but will not scale.
rails new
application-nameapplication-name is the name of your
application)Gemfile.lockGemfile.lock makes sure that exactly the same gems are used
for development, test, and productionrails new creates many
directories, subdirectories and files.app: The main application filesconfig: Configuration filesdb: Database-related filespublic: Files that are served directlytest: Files for testinglib, log,
storage, tmp, vendor app Directorymodels: Models (ActiveRecord) used by the
applicationviews: Views (ERB) used by the applicationcontrollers: Controllers used by the applicationassets, channels,
helpers, jobs, mailers
app directoryApplicationControllerActionController::Base)ExampleController is at
app/controllers/example_controller.rb@var),
which can be accessed by the viewapp/view, with subdirectory for each controller
(class)app/view/controller/action.html.erbbody content (head,
<body>/</body> tags added
automatically)config/routes.rbrails routesrails new: create a new rails applicationrails generate: generate some files (e.g. for a controller
and associated view,...)rails server: start the rails serverrails routes: show the routes for this applicationAll commands except rails new have to be executed in the
application directory.
development environment (see
config/environments)test and
productionrails new
hellocd hellorails serverrails s)http://localhost:3000/Rails version: . . . . . . . . . . . .
Ruby version: . . . . . . . . . . . . . . . .
data: URIsyay.htmlyay.html to Moodle (deadline 17:00)rails generate controller Say hellohttp://localhost:3000/say/helloController method: . . . . . . . . . . # . . . . . . . . . .
Location of view file: . . . . . . . . . . . . . . . . . . . . . . . .
h1) of
Hello from [your name here]!app/controllers/say_controller.rb),
set the instance variable @time to the current time
(Time.now)@time to output
The current time is .....say_controller.rb and
hello.html.erb to Moodle (deadline 17:45)goodbye in the Say
controllerhello.html.erb file to
goodbye.html.erbGoodbye from [your
name here]!config/routes.rb, add an additional lineget 'say/goodbye'http://localhost:3000/say/goodbyerails
routes to show the routes in your application.rails_service_blob)routes.txt with a
redirectparams[:count] to
access the count URI parameter@count instance variable to the integer value of
the count parametercount parameter, or the value of
count is 0 or smaller, set @count to 1goodbye.html.erb file, use the
@count instance variable to repeat Goodbye!
count timeshttp://localhost:3000/say/goodbye?count=5, many other
count values (incl. negative and non-numeric), and with no
count parametersay_controller.rb,
goodbye.html.erb, and routes.txt to Moodle
(deadline 18:20)Find at least 3 explanations on the Web about MVC. Read and compare them.