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

You dont need this in the controller because you're finding all locations in
the view itself.

>Is there a better way to handle the  && params[:location][:id].to_i >=
1 it's the way I thought to do it?
&& !(params[:location][:id].blank?)

or

!(params[:location].blank?)

whatever works for you. You can see i love blank? :)

 Ideally, this whole functionality should go into the model.

Create a teacher.full_name method. Its simple.

On Tue, May 12, 2009 at 4:41 PM, bingo bob <[email protected]
> wrote:

>
>
> 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/.
>
> >
>


-- 
In Sport We Trust !!!

--~--~---------~--~----~------------~-------~--~----~
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 [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to