# Please help... I'm stuck with this link\_to problem

**URL:** <https://www.ruby-forum.com/t/please-help-im-stuck-with-this-link-to-problem/131892>\
**Category:** Rails\
**Created:** [March 14, 2008, 5:25am UTC](https://www.ruby-forum.com/t/please-help-im-stuck-with-this-link-to-problem/131892 "2008-03-14T05:25:52Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![adi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@adi](https://www.ruby-forum.com/u/adi)\
**Post date:** [March 14, 2008, 5:25am UTC](https://www.ruby-forum.com/t/please-help-im-stuck-with-this-link-to-problem/131892/1 "2008-03-14T05:25:52Z")

</div>

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

* * *

: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…

---

<div class="post-metadata">

**Author:** ![adi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@adi](https://www.ruby-forum.com/u/adi)\
**Post date:** [March 14, 2008, 8:29am UTC](https://www.ruby-forum.com/t/please-help-im-stuck-with-this-link-to-problem/131892/2 "2008-03-14T08:29:03Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![adi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@adi](https://www.ruby-forum.com/u/adi)\
**Post date:** [March 14, 2008, 9:57am UTC](https://www.ruby-forum.com/t/please-help-im-stuck-with-this-link-to-problem/131892/3 "2008-03-14T09:57:11Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![adi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@adi](https://www.ruby-forum.com/u/adi)\
**Post date:** [March 14, 2008, 10:40am UTC](https://www.ruby-forum.com/t/please-help-im-stuck-with-this-link-to-problem/131892/4 "2008-03-14T10:40:13Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![adi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@adi](https://www.ruby-forum.com/u/adi)\
**Post date:** [March 14, 2008, 10:08am UTC](https://www.ruby-forum.com/t/please-help-im-stuck-with-this-link-to-problem/131892/5 "2008-03-14T10:08:10Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![adi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@adi](https://www.ruby-forum.com/u/adi)\
**Post date:** [March 14, 2008, 10:52am UTC](https://www.ruby-forum.com/t/please-help-im-stuck-with-this-link-to-problem/131892/6 "2008-03-14T10:52:08Z")

</div>

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”)?

---

<div class="post-metadata">

**Author:** ![adi](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/4da419/32.png) [@adi](https://www.ruby-forum.com/u/adi)\
**Post date:** [March 14, 2008, 1:06pm UTC](https://www.ruby-forum.com/t/please-help-im-stuck-with-this-link-to-problem/131892/7 "2008-03-14T13:06:56Z")

</div>

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](http://blog.odeley.com)
