New and lost


#1

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?


#2

On 3/9/06, Rich H. removed_email_address@domain.invalid 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?

Have you created the model? (script/generate create model Birthday)

Have you created a controller?

Specifically, you probably want something like:

@birthdays_this_month = Birthdays.find(:all, :conditions => "month =
"+Time.now.month.to_s)

I don’t mean to be rude, but I would suggest you start off with one of
the
tutorials or videos (http://www.rubyonrails.org/docs) and let it guide
you
through some of these early questions, before starting your own project.

– Joshua


#3

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:

app/controllers/birthdays_controller.rb:

class BirthdaysController < ApplicationController
def show
@people = Person.find_all_by_month(params[:month])
end
end

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/
birthdays/show.rhtml:

    <% 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
birthdays).

Duane J.
(canadaduane)
http://blog.inquirylabs.com/