Ruby on Rails: first project notes

Following creates project, controller and run HTTP server (default port: 3000)

rails first
cd first
ruby script/generate controller Somecontroller
ruby script/server

Edit Somecontroller controller responses:

vi app/controllers/Somecontroller_controller.rb

Add views (there.rhtml) for Somecontroller:

class HelloController < ApplicationController
++ def there
++ end
end

Creating view for Somecontroller and running view in webbrowser:

cd apps/views
echo "<html>Hello first test</html>" >> there.rhtml
firefox 127.0.0.1:3000/somecontroller/there

So what is what in app:

├── app
│   ├── controllers
│   │   ├── application_controller.rb
│   │   └── somecontroller_controller.rb
│   ├── helpers
│   │   ├── application_helper.rb
│   │   └── somecontroller_helper.rb
│   ├── models
│   └── views
│       ├── somecontroller
│       │   └── there.rhtml
│       └── layouts

What does somecontroller_helper.rb contains?

cat app/helpers/somecontroller_helper.rb
 
module SomecontrollerHelper
end

RoR architecture

Webbrowser -> Controller -> Action -> View
   ^                                   │
   └────────────────────────────────────

Action can work/interact with some sort of model.

Modifying of there.rhtml

<html>
  <head>
    <title>Some title</title>
  </head>
  <body>
    <h1>Hello</h1>
    This is a first app in RoR<br><br>
 
 
    You will see nothing here: (executed but not displayed; a will become 5):
    <div style="background:black;color:white; width=100px;">
      <% a = 2 + 3 %>
    </div>
 
 
    This will be displayed as 5:
    <div style="background:black;color:white; width:100px;">
      <%= a %>
    </div><br>
 
    <b>Sort of loop:</b><br>
      <% 5.times do %>
      Yes! <br>
      <% end %>
 
 
    <b>Displaying of range a..z:</b><br>
      <% ("a".."z").each { |i| %>
      <%= i %><br>
      <% } %><br>
 
    <b>Or same range in one line:</b><br>
      <% ("a".."z").each { |i|%> <%= i %><% } %>
 
  </body>
</html>