Hi.
Ive run into a problem when trying to create scaffold code and using
database tables that have the underscore character in them. I have 2
tables, my_users and my_privileges. my_user has a foreign key that
links into my_privileges.
So what I did was generate scaffold code with the following lines:
ruby script/generate scaffold my_user
ruby script/generate scaffold my_privilege
In models/my_user.rb I added:
belongs_to :my_privilege
And in models/my_privilege.rb I added:
has_many :my_users
Then in the views/my_users/show.rhtml, I added the following line:
<%= @my_user.my_privilege.name %>
However, I then get the following error:
"You have a nil object when you didn''t expect it!
The error occurred when evaluating nil.name"
I then tried all this without the underscore in the table name, using
users and privileges as the tables names, and then generated the
scaffold code witht the following lines:
ruby script/generate scaffold user
ruby script/generate scaffold privilege
And then added the following to models/user.rb
belongs_to :privilege
And the following to models/privilege.rb
has_many :users
And then in views/users/show.rhtml, I have the following line:
<%= @user.privilege.name %>
And this works fine, and shows the name field in the privileges table.
So what I would like to know, is what is the correct way to generate
scaffold code that will be using a table with the underscore character
in it? Is there another way to do this or is there perhaps something
that I am doing wrong?
Any help or suggestions would be appreciated.
Regards.
/Cole
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Ruby on Rails: Talk" group.
To post to this group, send email to
rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
To unsubscribe from this group, send email to
rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---