Ramaze Wiki
History
Table of Contents
  1. Frequently Asked Questions
    1. Why does Ramaze seem to have so many dependencies?
    2. no such file to load -- ramaze (LoadError)
    3. Can I run different Ramaze versions for different Ramaze applications?
    4. Why aren't my template files being used?
    5. How do I use a different view for an action?
    6. How do I do routing?
    7. How do I dynamically choose a layout?
    8. Why are my flash messages showing up for two requests instead of just one?
    9. How do I handle file uploads?
    10. How do I get Ramaze to serve static files?
    11. How do I handle exceptions or errors, or set custom 404 pages?
    12. How do you pronounce Ramaze?
    13. Where is the issue/bug tracker?
    14. Logging
      1. How do I print to the log?
      2. How do I turn off DEBUG and INFO messages?
      3. How do I save logs to file?
    15. How do I set Ramaze options?

Frequently Asked Questions


Why does Ramaze seem to have so many dependencies?


Ramaze only has two gem dependencies:

- innate
- rack (needed by innate)

If 'gem install ramaze' pulls more than that, it means you are using an old version of RubyGems which does not distinguish between development dependencies (which are optional) and required dependencies. Those "so many" dependencies are only used for development and testing and are not actually required for end users using Ramaze. The solution is to upgrade RubyGems to a sufficiently recent version (1.3.x or higher).

no such file to load -- ramaze (LoadError)


Problem symptom:

  start.rb:1:in `require': no such file to load -- ramaze (LoadError) from start.rb:1

Solutions (choose one):

- ruby -rrubygems start.rb
- export RUBYOPT=-rrubygems
- require 'rubygems' # before require 'ramaze'

Can I run different Ramaze versions for different Ramaze applications?


Certainly! Just choose a specific gem version in your application, like this:

require 'rubygems'
gem 'ramaze', '2009.03'
require 'ramaze'

See also RVM and its gemsets.

Why aren't my template files being used?


Make sure your template files have the right extension for the template engine you are using.

Also make sure you're putting them in the directory that Ramaze is
looking for templates. By default, this is the view/ subdirectory.

How do I use a different view for an action?


Ramaze automatically uses a view file that matches the action method. To use a different one, use respond in the method:

respond(render_view(:another_view))

Alternatively, you can alias views:

# Use the 'instead' view when hitting 'requested'
alias_view 'requested', 'instead'

How do I do routing?


To route requests for /foo to be handled by /bar:

  Innate::Route[ '/foo' ] = '/bar'

See the Innate::Route documentation for more examples and info on doing more complex routing (such as with regular expressions or lambdas).

How do I dynamically choose a layout?


See Ramaze::Helper::Layout.

If your layout needs are more complex than that, you can:

  # class MyController
  # ...
    layout { |path,wish|
      case path
      when /foo/
        'some_layout'
      when /bar/
        'some_other_layout'
      end
    }

Why are my flash messages showing up for two requests instead of just one?


Flash messages expire after the next hit (HTTP request). If you are seeing
the flash message persist for two requests, that usually means you are
displaying the flash message on the current hit. If flash messages were
cleared after the current hit, then they could not be used in redirection.
Generally, the flash hash should only be used together with redirection.

How do I handle file uploads?


See the file upload example in the examples directory.

How do I get Ramaze to serve static files?


By default, Ramaze will attempt to serve any files found in the
public/ directory of your application (relative to the file with
Ramaze.start in it). For example, if you have a file
public/foo/bar.pdf, you can download it by browsing to
http://mydomain.com/foo/bar.pdf. You can change the public path using
Ramaze.options.public_root = 'some/new/path'

How do I handle exceptions or errors, or set custom 404 pages?


Use Rack to route particular exceptions to particular actions. For example, to catch all exceptions and route them to the error action of your MainController:

Rack::RouteExceptions.route( Exception, MainController.r( :error ) )

How do you pronounce Ramaze?


In English, the official pronunciation is like the English 'amaze' with a prefixed 'r'.

wp:International Phonetic Alphabet transcription:
ɹʌˈmejz

In non-English, an acceptable alternative is:

'ra' as in 'romp'
'ma' as in 'mark'
'ze' as in 'zest'

or, using wp:International Phonetic Alphabet transcription:
ɹaˈmazɛ
ɾaˈmazɛ

or, using japanese Katakana:
ラマゼ

Where is the issue/bug tracker?


There is no official issue tracking software in place. A couple of probable reasons for this:

Nevertheless, if you feel that you must use an issue tracker in lieu of the mailing list and IRC channel, then submit a new ticket here.

Logging


Ramaze is using the Logger library of Ruby stdlib by default, but allows you to dispatch logging to multiple loggers at once as long as they respond to #log(level, *messages).

How do I print to the log?


Ramaze::Log.debug "some debug message"
Ramaze::Log.warn "some warning message"
Ramaze::Log.info "some info message"

How do I turn off DEBUG and INFO messages?


Ramaze::Log.level = Logger::WARN

The levels available, along with their precedence are:

DEBUG < INFO < WARN < ERROR < FATAL < UNKNOWN

To turn off all logging:

  Ramaze::Log.loggers.clear

How do I save logs to file?


Some of the capabilities from the Logger library allow you to do following:

# 1. Create logger for stderr/stdout
logger = Logger.new($stdout)
logger = Logger.new($stderr)

# 2. Create logger for a file
logger = Logger.new('test.log')

# 3. Create logger for file object
file = File.open('test.log', 'a+')
logger = Logger.new(file)

# 4. Create logger with rotation on specified file size

# 10 files history, 5 MB each
logger = Logger.new('test.log', 10, (5 << 20))

# 100 files history, 1 MB each
logger = Logger.new('test.log', 100, (1 << 20))

# 5. Create a logger which ages logfiles daily/weekly/monthly

logger = Logger.new('test.log', 'daily')
logger = Logger.new('test.log', 'weekly')
logger = Logger.new('test.log', 'monthly')

So, to simply log to $stderr and to a file, you can

stderr_logger = Logger.new($stderr)
file_logger = Logger.new('ramaze.log')
Ramaze::Log.loggers = [stderr_logger, file_logger]

A logger with log-rotation without output to $stderr (useful for FCGI) would look like this:

rotating_logger = Logger.new('ramaze.log', 'daily')
Ramaze::Log.loggers = [rotating_logger]

How do I set Ramaze options?


Via Ramaze.start:

Ramaze.start :adapter => :mongrel, :port => 8080

Via Ramaze.options:

Ramaze.options.adapter.port = 8080
Ramaze.options.adapter.handler = :mongrel

See options.rb and Journey to Ramaze: Configuration