In PHP, the basic assumption is that the whole file will be a template. This means that in order to actually do anything in PHP, you have to tell the interpreter to pay attention.
In general, this isn’t the case in Ruby. Your average Ruby file starts off as Ruby code, and doesn’t drop out to HTML anywhere.
The one place this isn’t true is in Rails’ views. These are ERb templates:
<% Ruby code -- inline with output %> <%= Ruby expression -- replace with result %> <%# comment -- ignored -- useful in testing %> % a line of Ruby code -- treated as <% line %> (optional -- see ERB.new) %% replaced with % if first thing on a line and % processing is used <%% or %%> -- replace with <% or %> respectively
ERb templates work a lot like php does normally, embedding ruby code inside html or another text based format. In the Rails world we use these for templating, and its generally a bad idea to put any serious functionality in here.
Instead most of your functionality should go in a Controller action. A Controller is a class, which contains public methods (“actions”) that can be called by users from their browser, its job is to process user input, and create any output information to be used after, in the view.
If you don’t yet know how to write Ruby code, jump on google and find yourself a tutorial. A nice quick intro is Try Ruby, it gives you a very quick interactive tutorial, where you write ruby code in to your web browser and see it run real time on their server, in your own isolated account. For a more advanced tutorial, check out Why’s (Poignant) Guide to Ruby.
In PHP, the basic assumption is that the whole file will be a template. This means that in order to actually do anything in PHP, you have to tell the interpreter to pay attention.
In general, this isn’t the case in Ruby. Your average Ruby file starts off as Ruby code, and doesn’t drop out to HTML anywhere.
The one place this isn’t true is in Rails’ views. These are ERb templates:
<% Ruby code -- inline with output %> <%= Ruby expression -- replace with result %> <%# comment -- ignored -- useful in testing %> % a line of Ruby code -- treated as <% line %> (optional -- see ERB.new) %% replaced with % if first thing on a line and % processing is used <%% or %%> -- replace with <% or %> respectively
ERb templates work a lot like php does normally, embedding ruby code inside html or another text based format. In the Rails world we use these for templating, and its generally a bad idea to put any serious functionality in here.
Instead most of your functionality should go in a Controller action. A Controller is a class, which contains public methods (“actions”) that can be called by users from their browser, its job is to process user input, and create any output information to be used after, in the view.
If you don’t yet know how to write Ruby code, jump on google and find yourself a tutorial. A nice quick intro is Try Ruby, it gives you a very quick interactive tutorial, where you write ruby code in to your web browser and see it run real time on their server, in your own isolated account. For a more advanced tutorial, check out Why’s (Poignant) Guide to Ruby.