Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Rename chapter files to reflect their title, order is kept only in th…

…e journey_to_ramaze.txt so reordering is simpler
  • Loading branch information...
commit 4dc6bbada5b40bebb97a42add4d89472dd068007 1 parent cff5435
Michael Fellinger authored
0  chapter/ch05.txt → chapter/actions.txt
File renamed without changes
0  chapter/ch06.txt → chapter/adapters.txt
File renamed without changes
4 chapter/ch08.txt
... ... @@ -1,4 +0,0 @@
1   -= Ramaze::Current
2   -== Some title
3   -
4   -Not much here
72 chapter/ch13.txt
... ... @@ -1,72 +0,0 @@
1   -= Ramaze::Session
2   -
3   -Sessions are an essential part of most dynamic web applications and so Ramaze makes it very simple to use them. We will see how to use the automated sessions, handle cookies manually and change the backend where session information is stored on the serverside.
4   -
5   -== What are sessions
6   -
7   -Although I said that they are essential, some people may not yet be familiar with sessions and what use cases exist for them, so let's take a look at a simple application using sessions first.
8   -
9   -
10   -[source,ruby]
11   ---------------------------------------------------------------------------------
12   -require 'ramaze'
13   -
14   -class MainController < Ramaze::Controller
15   - HELLO = {
16   - 'en' => "Hello, world!",
17   - 'de' => "Hallo Welt!",
18   - 'it' => "Ciao, mondo!",
19   - }
20   -
21   - def index
22   - language = HELLO.keys.sort_by{ rand }.first
23   - session[:language] = language
24   - redirect Rs(:greet)
25   - end
26   -
27   - def greet
28   - HELLO[session[:language]]
29   - end
30   -end
31   ---------------------------------------------------------------------------------
32   -
33   -
34   -In this, we select a random language key that we then set in our session. The browser that hits the index action will from now on always have this language associated to it and you can see it in your controller and templates inside the session object.
35   -
36   -Now a few details on how this works exactly.
37   -
38   -
39   -
40   -On every request, as we mentioned in the chapter about Ramaze::Current already, a Session is initialized and put into `Ramaze::STATE[:session]`. This makes it possible to access the session during the whole request. The initialization will set a cookie in the current response, setting the key `_ramaze_session_id` with a unique value representing the key to the data stored on the server.
41   -
42   -Cookies are basically a part of the response headers, a simple string that is being sent back and forth during the request/response cycle. Everytime a browser sends a request it will also send the cookie in the header with it, that way we can look up which data belongs to that browser.
43   -
44   -In Ramaze this data is stored in a cache, at the time of writing the two most commonly used ones are MemcachedCache and MemoryCache.
45   -
46   -
47   -
48   -Although they may sound similar, they are quite different concepts, MemoryCache equals a Ruby Hash, it doesn't put any restrains on the kind or amount of data stored, which can become problematic for larger applications. MemcachedCache on the other hand utilizes the MemCache library to communicate with an (usually) local memcache daemon that handles caching of key/value pairs in namespaces. It allows you to control the way caching happens very well, one commonly used option is to put a limit on the overall amount of data stored. However, old data is thrown away if your application tries to cache more data than allowed.
49   -
50   -There is a third way which was contributed recently, to utilize the Sequel ORM and use a relational database for storage, which gives both control and persistence as old data is never thrown away unless explicitly ordered to do so.
51   -
52   -== Configuration
53   -
54   -A number of options lets you decide how to use sessions and their behaviour.
55   -
56   -To disable them, simply assign:
57   -
58   -[source,ruby]
59   ---------------------------------------------------------------------------------
60   -Ramaze::Global.sessions = false
61   ---------------------------------------------------------------------------------
62   -
63   -This will give you some speedup and less data being transferred between server and client, it does not affect the ability to manually set cookies in the response.
64   -
65   -To change the backend for the session cache only (as opposed to it for all caches in your Ramaze, we talk about that in the Ramaze::Cache section) do following:
66   -
67   -[source,ruby]
68   ---------------------------------------------------------------------------------
69   -Ramaze::Global.cache_alternative[:sessions] = Ramaze::MemcachedCache
70   ---------------------------------------------------------------------------------
71   -
72   -Please make sure you have the memcached server running before starting an application with this setting.
0  chapter/ch04.txt → chapter/configuration.txt
File renamed without changes
0  chapter/ch07.txt → chapter/controllers.txt
File renamed without changes
0  chapter/ch09.txt → chapter/helpers.txt
File renamed without changes
0  chapter/ch10.txt → chapter/installation.txt
File renamed without changes
0  chapter/ch11.txt → chapter/requests.txt
File renamed without changes
0  chapter/ch12.txt → chapter/responses.txt
File renamed without changes
0  chapter/ch16.txt → chapter/security.txt
File renamed without changes
0  chapter/ch02.txt → chapter/sessions.txt
File renamed without changes
0  chapter/ch14.txt → chapter/templating.txt
File renamed without changes
0  chapter/ch15.txt → chapter/trinity.txt
File renamed without changes
0  chapter/ch01.txt → chapter/tutorial_introduction.txt
File renamed without changes
49 journey_to_ramaze.txt
@@ -6,50 +6,33 @@ v0.2, March 2009
6 6
7 7 include::chapter/preface.txt[tabsize=2]
8 8
9   -// Tutorial introduction to Ramaze
10   -include::chapter/ch01.txt[tabsize=2]
11   -
12   -// Sessions
13   -include::chapter/ch02.txt[tabsize=2]
14   -
15   -// include::chapter/ch03.txt[tabsize=2]
  9 +// Contains links and other snippets used all over the book
  10 +include::chapter/attributes.txt[tabsize=2]
16 11
17   -// Configuration
18   -include::chapter/ch04.txt[tabsize=2]
  12 +include::chapter/tutorial_introduction.txt[tabsize=2]
19 13
20   -// Action
21   -include::chapter/ch05.txt[tabsize=2]
  14 +include::chapter/sessions.txt[tabsize=2]
22 15
23   -// Adapters
24   -include::chapter/ch06.txt[tabsize=2]
  16 +// chapters below are old content and need major rework
25 17
26   -// Controllers
27   -include::chapter/ch07.txt[tabsize=2]
  18 +include::chapter/configuration.txt[tabsize=2]
28 19
29   -// include::chapter/ch08.txt[tabsize=2]
  20 +include::chapter/actions.txt[tabsize=2]
30 21
31   -// Helpers
32   -include::chapter/ch09.txt[tabsize=2]
  22 +include::chapter/adapters.txt[tabsize=2]
33 23
34   -// Installation
35   -include::chapter/ch10.txt[tabsize=2]
  24 +include::chapter/controllers.txt[tabsize=2]
36 25
37   -// Requests
38   -include::chapter/ch11.txt[tabsize=2]
  26 +include::chapter/helpers.txt[tabsize=2]
39 27
40   -// Responses
41   -include::chapter/ch12.txt[tabsize=2]
  28 +include::chapter/installation.txt[tabsize=2]
42 29
43   -// Sessions
44   -include::chapter/ch13.txt[tabsize=2]
  30 +include::chapter/requests.txt[tabsize=2]
45 31
46   -// Templating
47   -include::chapter/ch14.txt[tabsize=2]
  32 +include::chapter/responses.txt[tabsize=2]
48 33
49   -// Trinity
50   -include::chapter/ch15.txt[tabsize=2]
  34 +include::chapter/security.txt[tabsize=2]
51 35
52   -// Security
53   -include::chapter/ch16.txt[tabsize=2]
  36 +include::chapter/templating.txt[tabsize=2]
54 37
55   -include::chapter/attributes.txt[tabsize=2]
  38 +include::chapter/trinity.txt[tabsize=2]

0 comments on commit 4dc6bba

Please sign in to comment.
Something went wrong with that request. Please try again.