views:

100

answers:

2

I have a "jobs" model in my RoR project and i need the controller to access a table other than "jobs" in the database.

Calling: @var = Job.find(:all) is not problem, but calling

@var = TableB.find(:all)

gets "undefined local variable or method `tableB'" for JobsController:Class

Any ideas? Thanks!

+1  A: 

Do you have a TableB model?

script/generate model TableB

You might also be trying to have a model that corresponds to a different table name (not sure exactly what you're asking):

class Job < ActiveRecord::Base 
    set_table_name 'TableB' 
end
zenazn
yes, I have a model TableB. both "Job" and "TableB" are tables and models in my Rails project. to rephrase my question, how do you get a controller to manipulate objects that are not in the controller's class? in this case, the controller is named "Jobs" and the class/model I need to manipulate is "tableB."
A: 

All models are available in all controllers.

So from your exact input I would say tableB != TableB could be the problem.

nasmorn
Yeah, I was thinking it's something along these lines. You shouldn't have any trouble getting the model from any controller, as long as you're following ActiveRecord naming conventions, i.e. singular camelcase starting with a capital letter.
Raphomet
thanks! i was using the filename - table_b.rb - instead of the actual class name - tableB.