On Mar 9, 2006, at 9:35 AM, Rich H. wrote:
I am very new with Ruby on Rails and most coding in general. I have
created a DB table with birthdays and names. The birthdays are split
into two fields (Month and Day). Using this table I would like to
display birthdays for the current month.
How can this be done?
Pretty broad question, but I might be able to take a quick gander.
First, assuming you’ve got your database.yml file set up to connect
to your database properly, add a controller, something like:
class BirthdaysController < ApplicationController
@people = Person.find_all_by_month(params[:month])
The above code assumes that (a) you have a model called Person that
(probably) maps to your DB table is called “people”, and (b) that you
have a route set up in routes.rb, like so:
map.connect ‘birthdays/show/:month’, :controller =>
‘birthdays’, :action => ‘show’
Next, you’d create the view for the ‘show’ action inside app/views/
<% for person in @people %>
- <%= person.name %>: <%= person.month %> / <%= person.day %>
<% end %>
Then you should be able to visit your view (once your server is
running) at http://localhost:3000/birthdays/show/8 (e.g. show August