Please help... I'm stuck with this link_to problem...

Hello,

Recently i tried to learn developing web using Ruby on Rails... In my learning, i tried to connect 2 different controller which is hospitals_controller and show_hospital_controller. Between those controller i need to pass a session named :addr, which will be passed when i click the <%= link_to 'Search', :controller => 'hospital', :action => 'redir' ). After the link clicked, it will go to

  def redir     session[:addr] = @address     redirect_to(:controller => 'main', :action => 'index' )   end

which will set a session value and redirect the page to :controller => 'main', :action => 'index'.

But when i clicked that link, i got an error page such as below :

  ActiveRecord::RecordNotFound in HospitalsController#show   Couldn't find Hospital with ID=redir   RAILS_ROOT: D:/Aptana/cari_toko

  Application Trace | Framework Trace | Full Trace   c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ base.rb:1267:in `find_one' c:/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.0.2/lib/active_record/base.rb:1250:in `find_from_ids' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ base.rb:504:in `find' vendor/plugins/geokit/lib/geo_kit/ acts_as_mappable.rb:109:in `find' app/controllers/ hospitals_controller.rb:19:in `show'-e:2:in `load'-e:2   c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ base.rb:1267:in `find_one' c:/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.0.2/lib/active_record/base.rb:1250:in `find_from_ids' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ base.rb:504:in `find' vendor/plugins/geokit/lib/geo_kit/ acts_as_mappable.rb:109:in `find' c:/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/base.rb:1158:in `send' c:/ruby/ lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb: 1158:in `perform_action_without_filters' c:/ruby/lib/ruby/gems/1.8/ gems/actionpack-2.0.2/lib/action_controller/filters.rb:697:in `call_filters' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/filters.rb:689:in `perform_action_without_benchmark' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ benchmarking.rb:68:in `perform_action_without_rescue' c:/ruby/lib/ruby/ 1.8/benchmark.rb:293:in `measure' c:/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' c:/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/rescue.rb:199:in `perform_action_without_caching' c:/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/caching.rb:678:in `perform_action' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ active_record/connection_adapters/abstract/query_cache.rb:33:in `cache' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ active_record/query_cache.rb:8:in `cache' c:/ruby/lib/ruby/gems/1.8/ gems/actionpack-2.0.2/lib/action_controller/caching.rb:677:in `perform_action' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/base.rb:524:in `send' c:/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/base.rb:524:in `process_without_filters' c:/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/filters.rb:685:in `process_without_session_management_support' c:/ruby/lib/ruby/gems/1.8/ gems/actionpack-2.0.2/lib/action_controller/session_management.rb: 123:in `process' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/base.rb:388:in `process' c:/ruby/lib/ruby/gems/1.8/ gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:171:in `handle_request' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/dispatcher.rb:115:in `dispatch' c:/ruby/lib/ruby/ gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb: 126:in `dispatch_cgi' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/ lib/action_controller/dispatcher.rb:9:in `dispatch' c:/ruby/lib/ruby/ gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb:112:in `handle_dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/ webrick_server.rb:78:in `service' c:/ruby/lib/ruby/1.8/webrick/ httpserver.rb:104:in `service' c:/ruby/lib/ruby/1.8/webrick/ httpserver.rb:65:in `run' c:/ruby/lib/ruby/1.8/webrick/server.rb: 173:in `start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start' c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start' c:/ruby/lib/ruby/ 1.8/webrick/server.rb:92:in `each' c:/ruby/lib/ruby/1.8/webrick/ server.rb:92:in `start' c:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start' c:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start' c:/ruby/ lib/ruby/gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb:62:in `dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/ servers/webrick.rb:66 c:/ruby/lib/ruby/site_ruby/1.8/rubygems/ custom_require.rb:27:in `gem_original_require' c:/ruby/lib/ruby/ site_ruby/1.8/rubygems/custom_require.rb:27:in `require' c:/ruby/lib/ ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:496:in `require' c:/ruby/lib/ruby/gems/1.8/gems/ activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/ lib/active_support/dependencies.rb:496:in `require' c:/ruby/lib/ruby/ gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39 c:/ruby/lib/ruby/ site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' script/server:3   c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ base.rb:1267:in `find_one' c:/ruby/lib/ruby/gems/1.8/gems/ activerecord-2.0.2/lib/active_record/base.rb:1250:in `find_from_ids' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/active_record/ base.rb:504:in `find' vendor/plugins/geokit/lib/geo_kit/ acts_as_mappable.rb:109:in `find' app/controllers/ hospitals_controller.rb:19:in `show' c:/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/base.rb:1158:in `send' c:/ruby/ lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/base.rb: 1158:in `perform_action_without_filters' c:/ruby/lib/ruby/gems/1.8/ gems/actionpack-2.0.2/lib/action_controller/filters.rb:697:in `call_filters' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/filters.rb:689:in `perform_action_without_benchmark' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/action_controller/ benchmarking.rb:68:in `perform_action_without_rescue' c:/ruby/lib/ruby/ 1.8/benchmark.rb:293:in `measure' c:/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/benchmarking.rb:68:in `perform_action_without_rescue' c:/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/rescue.rb:199:in `perform_action_without_caching' c:/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/caching.rb:678:in `perform_action' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ active_record/connection_adapters/abstract/query_cache.rb:33:in `cache' c:/ruby/lib/ruby/gems/1.8/gems/activerecord-2.0.2/lib/ active_record/query_cache.rb:8:in `cache' c:/ruby/lib/ruby/gems/1.8/ gems/actionpack-2.0.2/lib/action_controller/caching.rb:677:in `perform_action' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/base.rb:524:in `send' c:/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/base.rb:524:in `process_without_filters' c:/ruby/lib/ruby/gems/1.8/gems/ actionpack-2.0.2/lib/action_controller/filters.rb:685:in `process_without_session_management_support' c:/ruby/lib/ruby/gems/1.8/ gems/actionpack-2.0.2/lib/action_controller/session_management.rb: 123:in `process' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/base.rb:388:in `process' c:/ruby/lib/ruby/gems/1.8/ gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb:171:in `handle_request' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/lib/ action_controller/dispatcher.rb:115:in `dispatch' c:/ruby/lib/ruby/ gems/1.8/gems/actionpack-2.0.2/lib/action_controller/dispatcher.rb: 126:in `dispatch_cgi' c:/ruby/lib/ruby/gems/1.8/gems/actionpack-2.0.2/ lib/action_controller/dispatcher.rb:9:in `dispatch' c:/ruby/lib/ruby/ gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb:112:in `handle_dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/ webrick_server.rb:78:in `service' c:/ruby/lib/ruby/1.8/webrick/ httpserver.rb:104:in `service' c:/ruby/lib/ruby/1.8/webrick/ httpserver.rb:65:in `run' c:/ruby/lib/ruby/1.8/webrick/server.rb: 173:in `start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start' c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in `start_thread' c:/ruby/lib/ruby/1.8/webrick/server.rb:95:in `start' c:/ruby/lib/ruby/ 1.8/webrick/server.rb:92:in `each' c:/ruby/lib/ruby/1.8/webrick/ server.rb:92:in `start' c:/ruby/lib/ruby/1.8/webrick/server.rb:23:in `start' c:/ruby/lib/ruby/1.8/webrick/server.rb:82:in `start' c:/ruby/ lib/ruby/gems/1.8/gems/rails-2.0.2/lib/webrick_server.rb:62:in `dispatch' c:/ruby/lib/ruby/gems/1.8/gems/rails-2.0.2/lib/commands/ servers/webrick.rb:66 c:/ruby/lib/ruby/site_ruby/1.8/rubygems/ custom_require.rb:27:in `gem_original_require' c:/ruby/lib/ruby/ site_ruby/1.8/rubygems/custom_require.rb:27:in `require' c:/ruby/lib/ ruby/gems/1.8/gems/activesupport-2.0.2/lib/active_support/ dependencies.rb:496:in `require' c:/ruby/lib/ruby/gems/1.8/gems/ activesupport-2.0.2/lib/active_support/dependencies.rb:342:in `new_constants_in' c:/ruby/lib/ruby/gems/1.8/gems/activesupport-2.0.2/ lib/active_support/dependencies.rb:496:in `require' c:/ruby/lib/ruby/ gems/1.8/gems/rails-2.0.2/lib/commands/server.rb:39 c:/ruby/lib/ruby/ site_ruby/1.8/rubygems/custom_require.rb:27:in `gem_original_require' c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in `require' script/server:3-e:2:in `load'-e:2   Request   Parameters:

  {"id"=>"redir"}

  Show session dump

you're using restful routes but haven't set a custom route for your redir method. you need to remove the map.resources :hospitals line and replace it with the following:

map.resources :hospitals, :collection => { :redir => :get }

then you can call:

<%= link_to 'Search', redir_hospitals_path %>

Mike

i've done just like what you said Mike... but it still give me the same error message... By the way, do you have any idea where to find tutorials or e-book that tell us about the routes in Ruby...???

Thank you,

Adi

Adi wrote:

i've done just like what you said Mike... but it still give me the same error message... By the way, do you have any idea where to find tutorials or e-book that tell us about the routes in Ruby...???

Did you restart the server? Route changes only take effect after a restart.

Google for "Rails REST routes" for all the details on resource routing.

yes i did restart the server. but it still showing error message...

Adi wrote:

yes i did restart the server. but it still showing error message...

Can you show the section of the log file before the error showing the full details of the controller call (from the line starting "Processing")?

what is the rendered HTML code rendered by "link_to 'Search', redir_hospitals_path " and what is the output of "rake routes"

maerzbow http://blog.odeley.com