Forum: Ruby on Rails RoR Listbox help

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.
2531c928aeb5340a8186d9c2a7a8937f?d=identicon&s=25 lindsm@gmail.com (Guest)
on 2008-12-04 09:58
(Received via mailing list)
Totally new to RoR, have done Riding on Rails Revisited and the
Getting started with Rails Tutorial.  Plus I have read why's poignant
guide on ruby (very helpful guide btw, helped me understand a lot.
After doing the cookbook2 tutorial, I'm redoing it attempting to
modify it to my needs.  I made a home controller (from the getting
started with ruby on rails guide) and deleted my index from public.  I
setup my routes correctly and the new home page comes up fine.  I have
a few tables in my MYSQL created and populated and my ROR app talking
to them.  One of the tables with sample data has 20k + records, so I
want to make a list box  my home page that filters it.  Had trouble
finding list boxes in the API but some google searching gave me some
good info (http://shiningthrough.co.uk/blog/show/6).

Following that mini tutorial and the API docs on collection_select I
tried creating a select box, whos option values are populated by my
database, on my index.html.erb page.  I am missing something really
obvious as the page now generates an no methoddefined error on my
collection_select line.

<%= collection_select( :geog, :areaname, @geogs, :area, :areaname,
{:prompt => true}) %>

Heres my geogs_controller.rb that was created using scaffolding.

class GeogsController < ApplicationController
  # GET /geogs
  # GET /geogs.xml
  def index
    @geogs = Geog.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @geogs }
    end
  end

  # GET /geogs/1
  # GET /geogs/1.xml
  def show
    @geog = Geog.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @geog }
    end
  end

  # GET /geogs/new
  # GET /geogs/new.xml
  def new
    @geog = Geog.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @geog }
    end
  end

  # GET /geogs/1/edit
  def edit
    @geog = Geog.find(params[:id])
  end

  # POST /geogs
  # POST /geogs.xml
  def create
    @geog = Geog.new(params[:geog])

    respond_to do |format|
      if @geog.save
        flash[:notice] = 'Geog was successfully created.'
        format.html { redirect_to(@geog) }
        format.xml  { render :xml => @geog, :status
=> :created, :location => @geog }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @geog.errors, :status
=> :unprocessable_entity }
      end
    end
  end

  # PUT /geogs/1
  # PUT /geogs/1.xml
  def update
    @geog = Geog.find(params[:id])

    respond_to do |format|
      if @geog.update_attributes(params[:geog])
        flash[:notice] = 'Geog was successfully updated.'
        format.html { redirect_to(@geog) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @geog.errors, :status
=> :unprocessable_entity }
      end
    end
  end

  # DELETE /geogs/1
  # DELETE /geogs/1.xml
  def destroy
    @geog = Geog.find(params[:id])
    @geog.destroy

    respond_to do |format|
      format.html { redirect_to(geogs_url) }
      format.xml  { head :ok }
    end
  end
end
This topic is locked and can not be replied to.