That looks great to me, so I’m now uber confused.
The error I get is this…
You have a nil object when you didn’t expect it!
You might have expected an instance of ActiveRecord::Base.
The error occurred while evaluating nil.[] (it’s erroring on the unless
params[:location][:id].empty? line)
with no params.
I implemented the following.
class WelcomeController < ApplicationController
def index
unless params[:location][:id].empty?
# location is set, so find it!
@location = Location.find(params[:location][:id])
else
# location is empty, so just get all the teachers
@teachers = Teacher.all
end
end
end
<% title “Welcome” %>
Find me in app/views/welcome/index.html.erb
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.
<% form_tag do %>
<%= select(“location”, “id”, Location.all.collect {|l| [ l.name, l.id
]}, {:prompt => ‘Any Location’}) %>
<%= submit_tag “go” %>
<% end -%>
<%= render :inline => params.inspect %>
<% if @teachers %>
<% for teacher in @teachers %>
<%= link_to [teacher.first_name + ’ ’ + teacher.last_name], teacher
%>
<%= teacher.email %>
Location: <%= teacher.location.name %>
Languages:
<% for language in teacher.languages %>
<%= language.name %>
<% end %>
<hr>
<% end %>
<% end %>
routes.
ActionController::Routing::Routes.draw do |map|
map.resources :languages
map.resources :locations
map.resources :teachers, :member => {:no_more_photo => :put}
map.login ‘login’, :controller => ‘teacher_sessions’, :action => ‘new’
map.logout ‘logout’, :controller => ‘teacher_sessions’, :action =>
‘destroy’
map.resources :teacher_sessions
The priority is based upon order of creation: first created ->
highest priority.
Sample of regular route:
map.connect ‘products/:id’, :controller => ‘catalog’, :action =>
‘view’
Keep in mind you can assign values other than :controller and
:action
Sample of named route:
map.purchase ‘products/:id/purchase’, :controller => ‘catalog’,
:action => ‘purchase’
This route can be invoked with purchase_url(:id => product.id)
Sample resource route (maps HTTP verbs to controller actions
automatically):
map.resources :products
Sample resource route with options:
map.resources :products, :member => { :short => :get, :toggle =>
:post }, :collection => { :sold => :get }
Sample resource route with sub-resources:
map.resources :products, :has_many => [ :comments, :sales ],
:has_one => :seller
Sample resource route with more complex sub-resources
map.resources :products do |products|
products.resources :comments
products.resources :sales, :collection => { :recent => :get }
end
Sample resource route within a namespace:
map.namespace :admin do |admin|
# Directs /admin/products/* to Admin::ProductsController
(app/controllers/admin/products_controller.rb)
admin.resources :products
end
You can have the root of your site routed with map.root – just
remember to delete public/index.html.
map.root :controller => “welcome”
map.root :controller => “welcome”
See how all your routes lay out with “rake routes”
Install the default routes as the lowest priority.
Note: These default routes make all actions in every controller
accessible via GET requests. You should
consider removing the them or commenting them out if you’re using
named routes and resources.
#map.connect ‘:controller/:action/:id’
#map.connect ‘:controller/:action/:id.:format’
end
======