2. Controllers
class MyTestController < ApplicationController
def index
render_text “Hello World”
end
end
def index():
return "Hello World"
3. Params
class MyTestController < ApplicationController
def index
render_text “Hello ”+params[:who]
end
end
def index():
return "Hello %s" % request.vars.who
def index():
return "Hello %s" % request.args[0]
4. Dispatching
http://hostname/MyTest/index
class MyTestController < ApplicationController
def index
render_text “Hello World”
end
end
http://hostname/myapp/mycontroller/index calls
def index():
return "Hello %s" % request.vars.who
5. Routing
routes.rb
routes.py (reversed routing, with or without
regex, IP filtering)
6. Views
<table>
<% @recipes.each do |recipe| %>
<tr>
<td><%= recipe.name %></td>
</tr>
<% end %>
</table>
<table>
{{for recipe in recipes:}}>
<tr>
<td>{{=recipe.name}}</td>
</tr>
{{pass}}
</table>
7. Passing vars in views
class MyTestController < ApplicationController
def index
@message=“Hello World”
end
end
def index():
return dict(message=”Hello World”)
8. Layouts
<title>Layout Example</title>
<body>
<%= yield %>
</body>
</html>
<title>Layout Example</title>
<body>
{{include}}
</body>
</html>
and in view:
{{extend ‘layout.html’}}
body