Reputation: 7967
Iam working in ruby on rails for fetching the existing db tables from remote server mechine(SQL SERVER) .Actually i don't know how to do this.Am following this way.please rectify me
My problem is while tying to run uninitialized constant TrDeviceDetailsController::TRDeviceDetail
is getting.
I set the following in database.yml
file.
development:
adapter: sqlserver
mode: odbc
database: BObd
dsn: newdb_64
username: ush
password: Ushu
host: ws1a20\SQLEXPRESS
The table exist in the db BOdb
is TRDeviceDetails
.I created models and controller using the command
rails generate model `TRDeviceDetail`
rails generate controller `TRDeviceDetails`
And in controller i put the following
class TrDeviceDetailsController < ApplicationController
def show
@devices = TRDeviceDetail.find(:all)
end
end
model file
class TrDeviceDetail < ActiveRecord::Base
# attr_accessible :title, :body
attr_accessible :UniqueDeviceID
end
where UniqueDeviceID
is the existing column in table TrDeviceDetails
and created a show.html.erb file for displaying the UniqueDeviceID
<h1>TrDeviceDetails#show</h1>
<p>Find me in app/views/tr_device_details/show.html.erb</p>
<%@device.inspect%>
what i need is,get existing tables from remote machine.How it is possible and why this error is occurring?
Upvotes: 1
Views: 964
Reputation: 29599
you should use
@devices = TrDeviceDetail.find(:all) # small 'r'
as the generated class is
class TrDeviceDetail < ActiveRecord::Base
UPDATE:
If the table name is not something that follows convention, you should set the table_name explicitly
class TrDeviceDetail < ActiveRecord::Base
set_table_name 'TRDeviceDetails'
end
Upvotes: 2