OK, Well I did what I did like this - it works. It's horribly complex
for what it is though, I don't mind the Array for now as I can
understand that part, I'd be very grateful to simplify the IF statements
though.
You can see what I need to do I hope - just have a drop down with a No
Filter option, the user should return to the index page after the drop
down with the selected city still highlighted - as I say this works but
it looks horrible and unsure how to do it right?
thanks
VIEW SAMPLE
========
<% form_tag do %>
<% cities_array = [["No Filter", 0]] + Location.all.map { |city|
[city.name, city.id] } %>
<% # cities_array.inspect %>
<% if params[:location_id] == "0" || params[:location_id] == nil %>
<%= select_tag (:location_id, options_for_select(cities_array, 0))%>
<% else %>
<%= select_tag (:location_id, options_for_select(cities_array,
@location.id))%>
<% end %>
<%= 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 %>
<hr>
<% end %>
<% end %>
CONTROLLER
========
class WelcomeController < ApplicationController
def index
@all_locations = Location.all
if params[:location_id] == "0" || params[:location_id] == nil # No
Filter Selected - ID 0
@location = nil
@teachers = Teacher.all
else
@location = Location.find(params[:location_id])
@teachers = @location.teachers
end
end
end
--
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 [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
-~----------~----~----~----~------~----~------~--~---