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:infind_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:infind’ app/controllers/
hospitals_controller.rb:19:in show'-e:2:inload’-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:infind_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:infind’ 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:inperform_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:inperform_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:inmeasure’ 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:inperform_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:incache’ 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:inperform_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:inprocess_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:inprocess’ 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:inhandle_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:indispatch_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:inhandle_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:inservice’ c:/ruby/lib/ruby/1.8/webrick/
httpserver.rb:65:in run' c:/ruby/lib/ruby/1.8/webrick/server.rb: 173:instart_thread’ c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in
start' c:/ruby/lib/ruby/1.8/webrick/server.rb:162:instart_thread’
c:/ruby/lib/ruby/1.8/webrick/server.rb:95:in start' c:/ruby/lib/ruby/ 1.8/webrick/server.rb:92:ineach’ c:/ruby/lib/ruby/1.8/webrick/
server.rb:92:in start' c:/ruby/lib/ruby/1.8/webrick/server.rb:23:instart’ 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:indispatch’ 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:inrequire’ 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:innew_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:ingem_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:infind_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:infind’ vendor/plugins/geokit/lib/geo_kit/
acts_as_mappable.rb:109:in find' app/controllers/ hospitals_controller.rb:19:inshow’ 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:inperform_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:inperform_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:inmeasure’ 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:inperform_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:incache’ 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:inperform_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:inprocess_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:inprocess’ 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:inhandle_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:indispatch_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:inhandle_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:inservice’ c:/ruby/lib/ruby/1.8/webrick/
httpserver.rb:65:in run' c:/ruby/lib/ruby/1.8/webrick/server.rb: 173:instart_thread’ c:/ruby/lib/ruby/1.8/webrick/server.rb:162:in
start' c:/ruby/lib/ruby/1.8/webrick/server.rb:162:instart_thread’
c:/ruby/lib/ruby/1.8/webrick/server.rb:95:in start' c:/ruby/lib/ruby/ 1.8/webrick/server.rb:92:ineach’ c:/ruby/lib/ruby/1.8/webrick/
server.rb:92:in start' c:/ruby/lib/ruby/1.8/webrick/server.rb:23:instart’ 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:indispatch’ 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:inrequire’ 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:innew_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:ingem_original_require’
c:/ruby/lib/ruby/site_ruby/1.8/rubygems/custom_require.rb:27:in
require' script/server:3-e:2:inload’-e:2
Request
Parameters:

{“id”=>“redir”}

Show session dump


:csrf_id: cebe51918fb10258a10bb706d67dcb8e
flash: !map:ActionController::Flash::FlashHash {}

Response
Headers:

{“cookie”=>[],
“Cache-Control”=>“no-cache”}

below are my routes.rb

ActionController::Routing::Routes.draw do |map|
map.resources :hospitals
map.connect ‘:controller/:action/:id’
map.connect ‘:controller/:action/:id.:format’
end

Can any one help me with this…

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

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

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.

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

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs