Running Ruby on built in Apache server on Mac

I'm trying to ease into Ruby and Rails. Is it possible to simply load a Ruby template file similar to the way I load a PHP file? The Mac built in Apache web server is preconfigured to support PHP, but I can't find out how to get it to support Ruby. Is there a simple way to add Ruby support? Can I even use Ruby this way without building a whole Rails app? Is there a better place to ask?

Thanks

I think the closest thing there is to what you’re looking for is mod_rails (aka Passenger) http://www.modrails.com/

Good install directions: http://www.robbyonrails.com/articles/2010/02/08/installing-ruby-on-rails-passenger-postgresql-mysql-oh-my-zsh-on-snow-leopard-fourth-edition

Hi, and of course you can just run Ruby stuff by itself. You don't need Rails if you are doing a Rails app... In the tutorial below you can start running Ruby programs as soon as you have Ruby installed in your system...

Cheers.

I went through and installed Passenger, says its started in the log. If I try to load a file from the webserver with extension .rb or .erb, I get the text file without having been processed by Ruby. Should this work? What else do I need to do to get a ruby template file to work?

Thanks

I went through and installed Passenger, says its started in the log. If I try to load a file from the webserver with extension .rb or .erb, I get the text file without having been processed by Ruby. Should this work? What else do I need to do to get a ruby template file to work?

Passenger is designed to run rack applications, these must be laid out on disk in a certain way ( http://www.modrails.com/documentation/Users%20guide.html#_deploying_a_rack_based_ruby_application ). This can be something very small - a sinatra app can be tiny!

Fred

So it sounds like I can't have Ruby process a standalone template file? So I can't use Ruby as a simple replacement for PHP without adhering more to an application convention for a framework?

I have a mostly static website that I use PHP for simple things, like handling including fragments of HTML that repeat on multiple pages.

It sounds like I can't reasonably use Ruby as a replacement for PHP in this situation?

I'd rather stick to one language and environment if I can. Sounds like I'd need to keep using PHP for my mostly static website and Ruby on Rails for my web apps. I had hoped to avoid two languages.

This is all very confusing. I've been googling...

I see references to .erb files, .rhtml and .erb.html files. Sounds like what I want to do can be done, but I don't get the impression its done very often because it doesn't seem very easy nor straightforward.

There used to be eRuby. But it sounds like you can use the erb module in Ruby instead.

I've found instructions where you can manually create a ruby script and a CGI command to run whatever extension you define in an Apache config file. Its an amazingly manual configuration process.

Does no one do this? Is it Ruby on Rails or bust? Can you use Ruby template files, ie Ruby embedded in HTML on an Apache webserver or do most folks just use PHP if this is needed and only use Ruby for web applications?

Thanks

david2 wrote:

This is all very confusing. I've been googling...

It's not really all that confusing, you're just confusing it all.

I see references to .erb files, .rhtml and .erb.html files. Sounds like what I want to do can be done, but I don't get the impression its done very often because it doesn't seem very easy nor straightforward.

Embedded Ruby (.erb). Ruby HTML (.rhtml). The .rhtml is an older convention that isn't used so much in newer versions of Rails. The rendering engine (.erb) has been separated from the template format (.html). This eases support for handling multiple representations of pages. For example you might have a different layout for mobile devices. The newer convention would allow you to name the two layouts accordingly, such as index.html.erb & index.mobile.erb. The later could still be HTML, but formatted for mobile devices. Both still use Embedded Ruby. There are also other engines, such as builder (index.xml.builder) and Ruby JavaScript (index.js.rjs).

I think where you might be getting confused is that in the case of PHP the "engine," or "intelligence," is wrapped up inside the Apache module. It's all that C code that really does the grunt work for PHP template rendering.

I've found instructions where you can manually create a ruby script and a CGI command to run whatever extension you define in an Apache config file. Its an amazingly manual configuration process.

Does no one do this? Is it Ruby on Rails or bust? Can you use Ruby template files, ie Ruby embedded in HTML on an Apache webserver or do most folks just use PHP if this is needed and only use Ruby for web applications?

You don't seem to be listening to the earlier replies. It is by no means Ruby on Rails or bust! There are many options ranging from the most fundamental Rack application, through Sinatra and all the way up to Rails.

As I said before, a lot of the "intelligence" of PHP is the Apache module itself. This might give you a false sense that PHP is simpler than a Ruby deployment. Maybe that's somewhat so, but it's also less flexible than something like Passenger Phusion (http://www.modrails.com/) + Rack (http://rack.rubyforge.org/). Phusion is a web interface that connects Apache (or Nginx) to any Rack application.

A Rack application can be as simple as:

class HelloWorld   def call(env)     [200, {"Content-Type" => "text/plain"}, ["Hello world!"]]   end end

If you just want to render some ERB templates then (as Frederick mentioned) Sinatra (Sinatra: README) is an excellent choice.

Given that a lot (now most) Ruby frameworks and web servers are based on Rack there is a lot of choice in the Ruby world. This is not a bad thing! It allows us to scale our solutions to target specific needs.

In your situation I would strongly suggest you look at Sinatra. I'm mean really look at it and not just glance at their home page.