Vinay - you nailed it. Many thanks.

I ended up with my controller like this....

#===========

class WelcomeController < ApplicationController
  def index

    # finding all the locations for the drop down
    @locations = Location.all


      if params[:commit] == "go" && params[:location][:id].to_i >= 1
        # location is set AND it's not a blank location id so find the 
teachers in the location
        @location = Location.find(params[:location][:id])
        @teachers = @location.teachers
      else
        # no form submitted so find just find all teachers
        @teachers = Teacher.all
      end

  end


end

#=========

Here's my view code..


<% title "Welcome" %>
<p>
Lorem ipsum dolor sit amet, consectetur adipisicing elit,
sed do eiusmod tempor incididunt ut labore et dolore magna aliqua.
Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris
nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in
reprehenderit in voluptate velit esse cillum dolore eu fugiat
nulla pariatur. Excepteur sint occaecat cupidatat non proident,
sunt in culpa qui officia deserunt mollit anim id est laborum.
</p>

<hr>

<% form_tag do %>

  <%= select("location", "id", Location.all.collect {|l| [ l.name, l.id 
]}, {:include_blank => true}) %>
  <%= submit_tag "go" %>

<% end -%>

<hr>

<% if @teachers %>
  <% for teacher in @teachers %>
    <%= link_to [teacher.first_name + ' ' + teacher.last_name], teacher 
%><br>
    <%= teacher.email %><br>
    Location: <%= teacher.location.name %><br>
    Languages:
    <% for language in teacher.languages %>
    <%= language.name %>
    <% end %>
    <hr>
  <% end %>
<% end %>

#============

Works great.

I'm interested to see any critique of this code? all comments 
appreciated.
Is there a better way to handle the  && params[:location][:id].to_i >= 1 
it's the way I thought to do it?

Many thanks to all for the comments here - very useful.
-- 
Posted via http://www.ruby-forum.com/.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Talk" group.
To post to this group, send email to rubyonrails-talk@googlegroups.com
To unsubscribe from this group, send email to 
rubyonrails-talk+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to