concept fragment in category rails

appears as: fragments, fragment, fragments
Rails 3 in Action

This is an excerpt from Manning's book Rails 3 in Action.

The second process is slightly different. Rather than storing the fragment as a file on the system, you will store it in memory and then access it through a key.

This time, Rails has written a fragment rather than writing a page. In this case, the fragment is actually the entire page, but it is the page available only for this user. When you request this page again, you’ll see this line in the server’s output:

Read fragment views/localhost:3000/projects/1 (0.3ms)

Upon the second request here, Rails has found the fragment pertaining to this request and served that instead. Rather than saving these files into the public directory, Rails instead saves them to the tmp/cache directory. Files that are in the public directory are automatically served by your web server without hitting the Rails stack, but cached responses in tmp/cache are served by the Rails stack itself. This may seem counterintuitive at first, but it’s really helpful if you want to alter what cache fragments are served to what user.