I have an existing DB and I want to develop an application that uses
this
existing DB. How do I import this DB into my application. What I mean
is, I
dont want to generate new models using rails, I want to use the existing
DB.
My DB contains tables named abc_profile, abc_friends and
abc_register.
One profile can have many friends and one profile can have one register.
What I have done is, I used the generate model script to generate the 3
models, and in the AbcProfile class, I wrote has_many :abc_friends and
also
wrote has_one :abc_register. In the AbcFriends class I wrote belongs_to
:abc_profile, and in the AbcRegister class I also wrote belongs_to
:abc_profile. Then I made a profile controller (generate controller
Profile)
and wrote in it @result = AbcProfile.find(:all).
In the app/views/profile/index.rhtml file, I wrote <% @result.each do
|res|
%>, but this line is giving an error. The error is
NoMethodError in Profile#index
Showing profile/index.rhtml where line #1 raised:
You have a nil object when you didn’t expect it!
You might have expected an instance of Array.
The error occurred while evaluating nil.each
Extracted source (around line #1):
1: <% @result.each do |res| %>
2:
3:
4:
Please help me with this error, and also guide me if I have done
anything
wrong in the above mentioned code. Also tell me about the table names
and
about the underscore in the table names, I mean do I write has_many
:abc_profile, or do I write has_many :AbcProfile.
I have an existing DB and I want to develop an application that uses
this existing DB. How do I import this DB into my application. What I mean
is, I dont want to generate new models using rails, I want to use the
existing DB.
If not set somewhere, models are more or less generated on the fly from
your
tables.
My DB contains tables named abc_profile, abc_friends and abc_register.
One profile can have many friends and one profile can have one register.
What I have done is, I used the generate model script to generate the 3
models, and in the AbcProfile class, I wrote has_many :abc_friends and also
wrote has_one :abc_register. In the AbcFriends class I wrote belongs_to
If not set elsehwere, table-names ought to be plural. Have you set this
according to your needs?
:abc_profile, and in the AbcRegister class I also wrote belongs_to
:abc_profile. Then I made a profile controller (generate controller
: Profile)
and wrote in it @result = AbcProfile.find(:all).
In the app/views/profile/index.rhtml file, I wrote <% @result.each do |res|
%>, but this line is giving an error. The error is
NoMethodError in Profile#index
Seems your controller’s index-Method is not found - it’s hard to say
what went
wrong, if you don’t show your controller completely (pastie.caboo.se is
your
friend)
3:
4:
@results is nil (in Java Terms null) 'cause it hasn’t been definied,
'cause
your controller wasn’t executed.
On Mon, 31 Dec 2007 16:42:53 +0500, Haris G. wrote:
I have an existing DB and I want to develop an application that uses
this existing DB. How do I import this DB into my application. What I
mean is, I dont want to generate new models using rails, I want to use
the existing DB.
here’s an example db which has been created by RoR:
Thanx a lot Jan and Thufir for your help. But now Im getting another
error
(and a weird one too). The page doesnt display anything, but the server
console says
ERROR Errno::ENOBUFS: An operation on a socket could not be performed
because the system lacked sufficient buffer space or because a queue was
full.
Thanx a lot Jan and Thufir for your help. But now Im getting another error
(and a weird one too). The page doesnt display anything, but the server
console says
ERROR Errno::ENOBUFS: An operation on a socket could not be performed
because the system lacked sufficient buffer space or because a queue was
full.
Looks like the server has some trouble accessing your DB or processing
results.
Is your database queried?
Did you modify config/database.yml according to your needs?