Forum: Ruby on Rails New and lost

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
Rich H. (Guest)
on 2006-03-09 18:35
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?
Josh on Rails (Guest)
on 2006-03-09 19:13
(Received via mailing list)
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
Duane J. (Guest)
on 2006-03-09 22:54
(Received via mailing list)
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:
<ul>
<% for person in @people %>
   <li><%= person.name %>: <%= person.month %> / <%= person.day %></li>
<% end %>
</ul>

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/
This topic is locked and can not be replied to.