Working with 2 tables in a Controller

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:intransfer2timesheet’

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:inmethod_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.

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

Hi Bill

Thanx for pointing out the typo error !