# New and lost

**URL:** <https://www.ruby-forum.com/t/new-and-lost/79082>\
**Category:** Rails\
**Created:** [March 9, 2006, 5:35pm UTC](https://www.ruby-forum.com/t/new-and-lost/79082 "2006-03-09T17:35:06Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bungle77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bungle77](https://www.ruby-forum.com/u/bungle77)\
**Post date:** [March 9, 2006, 5:35pm UTC](https://www.ruby-forum.com/t/new-and-lost/79082/1 "2006-03-09T17:35:06Z")

</div>

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?

---

<div class="post-metadata">

**Author:** ![bungle77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bungle77](https://www.ruby-forum.com/u/bungle77)\
**Post date:** [March 9, 2006, 6:13pm UTC](https://www.ruby-forum.com/t/new-and-lost/79082/2 "2006-03-09T18:13:58Z")

</div>

On 3/9/06, Rich H. [removed\_email\_address@domain.invalid](mailto: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](http://www.rubyonrails.org/docs)) and let it guide  
you  
through some of these early questions, before starting your own project.

– Joshua

---

<div class="post-metadata">

**Author:** ![bungle77](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/b/c67d28/32.png) [@bungle77](https://www.ruby-forum.com/u/bungle77)\
**Post date:** [March 9, 2006, 9:54pm UTC](https://www.ruby-forum.com/t/new-and-lost/79082/3 "2006-03-09T21:54:46Z")

</div>

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](http://localhost:3000/birthdays/show/8) (e.g. show August  
birthdays).

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