# Working with 2 tables in a Controller

**URL:** <https://www.ruby-forum.com/t/working-with-2-tables-in-a-controller/117918>\
**Category:** Rails\
**Created:** [October 22, 2007, 12:59pm UTC](https://www.ruby-forum.com/t/working-with-2-tables-in-a-controller/117918 "2007-10-22T12:59:51Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![CCH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/898d66/32.png) [@CCH](https://www.ruby-forum.com/u/CCH)\
**Post date:** [October 22, 2007, 12:59pm UTC](https://www.ruby-forum.com/t/working-with-2-tables-in-a-controller/117918/1 "2007-10-22T12:59:51Z")

</div>

Hi

a) I have 2 tables, namely workplans and timesheets.  
b) What I am trying to do is to add a custom link to AS List … OK

c) Then, when I click this link eg ‘transfer2timesheet’, a new record  
will then be created in the timesheets table and populated with the  
values from the workplan table

d) I added a transfer2timesheet method after the local config block  
in workplans controller as follows :-

class WorkplansController \< ApplicationController  
active\_scaffold :workplan do |config|  
config.columns  
=[:calen\_date,:staff,:customer,:category,:work\_plan,:no\_of\_hrs,  
:where\_work]

```
config.action_links.add 'transfer2timesheet', :label

```

=\>‘Transfer’, :type =\> :record, :page =\> false  
end

def transfer2timesheet  
newtimesheet=Timesheet.new  
newtimesheet=User.current\_user.login  
sourcetable=Workplan.find(Param[:id]) # this where the 500  
error is triggered  
newtimesheet.where\_work=sourcetable.where\_work  
newtimesheet.save  
end  
end

Result : 500 error

Processing WorkplansController#transfer2timesheet (for 127.0.0.1 at  
2007-10-21 22:58:54) [GET]  
Session ID: 072faf9dce18c4052cdc6a3386ec724c  
Parameters: {“adapter”=\>"\_list\_inline\_adapter", “\_method”=\>“get”,  
“action”=\>“transfer2timesheet”, “id”=\>“6686”,  
“controller”=\>“workplans”}

NameError (uninitialized constant WorkplansController::Param):  
C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activesupport-1.4.4/  
lib/active\_support/dependencies.rb:477:in `const_missing' D:/Aptana_Workspace/crm4web/app/controllers/ workplans_controller.rb:83:in`transfer2timesheet’

e) I have also tried

def transfer2timesheet  
newtimesheet=Timesheet.new  
newtimesheet=User.current\_user.login  
newtimesheet.where\_work=Workplan.where\_work # this where the 500  
error is triggered  
newtimesheet.save  
end  
end

Result : 500 error

Processing WorkplansController#transfer2timesheet (for 127.0.0.1 at  
2007-10-21 23:23:56) [GET]  
Session ID: 072faf9dce18c4052cdc6a3386ec724c  
Parameters: {“adapter”=\>"\_list\_inline\_adapter", “\_method”=\>“get”,  
“action”=\>“transfer2timesheet”, “id”=\>“6686”,  
“controller”=\>“workplans”}

NoMethodError (undefined method `where_work' for Workplan:Class): C:/InstantRails/ruby/lib/ruby/gems/1.8/gems/activerecord-1.15.5/ lib/active_record/base.rb:1238:in`method\_missing’  
D:/Aptana\_Workspace/crm4web/app/controllers/  
workplans\_controller.rb:84:in `transfer2timesheet’

Any assistance to resolve the error in (d) and (e) is greatly  
appreciated.

TIA.

---

<div class="post-metadata">

**Author:** ![CCH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/898d66/32.png) [@CCH](https://www.ruby-forum.com/u/CCH)\
**Post date:** [October 22, 2007, 6:19pm UTC](https://www.ruby-forum.com/t/working-with-2-tables-in-a-controller/117918/2 "2007-10-22T18:19:25Z")

</div>

Hi,

CCH wrote:

> sourcetable=Workplan.find(Param[:id])
> 
> # this where the 500 error is triggered

If you’re trying to use a value in the params hash, the syntax would  
be…  
Workplan.find(params[:id])

HTH,  
Bill

---

<div class="post-metadata">

**Author:** ![CCH](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/898d66/32.png) [@CCH](https://www.ruby-forum.com/u/CCH)\
**Post date:** [October 23, 2007, 10:28am UTC](https://www.ruby-forum.com/t/working-with-2-tables-in-a-controller/117918/3 "2007-10-23T10:28:09Z")

</div>

Hi Bill

Thanx for pointing out the typo error !
