On Sat, 2006-04-15 at 21:27 -0700, Brian V Hughes wrote:
same
classes/ActiveRecord/Associations/ClassMethods.html#M000533>. You’ll
which would have a ID column, along with the two foreign keys, and
whatever other columns you needed to keep track of data relative to
the join entries. The URL that I put above also has the info for
has_many :through as does Josh’s Typo blog, since he’s kind of the
“has_many :through” guy.
i recommend checking out his posts on the
topic, at http://www.hasmanythrough.com/.
OK - I refactored and got it all working today simply using the join
tables but removing the ‘roles_users.rb’ model
Life seemed to be good and I was able to get through all of the issues
of editing/deleting/adding new records to the join table and they work.
I then committed my changes to the repository and updated my live system
and find that I am now getting an error when using the join model in
controller…
The error…
Processing LoginController#user_rights (for 192.168.3.7 at 2006-04-16
18:35:04) [GET]
Session ID: 161d2b0f800a1069937f11381201e1b7
Parameters: {“action”=>“user_rights”, “id”=>“17”,
“controller”=>“login”}
NameError (uninitialized constant RolesUsers):
/usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:100:in
const_missing' /usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:131:in
const_missing’
/usr/lib/ruby/gems/1.8/gems/activesupport-1.3.1/lib/active_support/dependencies.rb:133:in
const_missing' /app/controllers/login_controller.rb:73:in
user_rights’
Where the line 73 in question is…
@roles_users = RolesUsers.find(:all,
:conditions => ["roles_users.user_id = ?", params[:id]],
:order => 'role_id'
)
and just for completeness…
Class Role has_and_belongs_to_many :users
Class User has_and_belongs_to_many :roles
and there is a populated table (from migrations) called roles_users
which was populated in this fashion (in a migration)…
User.find(:all).each { |u| u.roles << Role.find(:first,
:conditions => ["id = ?", 3]) }
and the same ‘version’ works at home (though I am using Fedora 4 at home
and RHEL 4 on the production system). Both have the same version of rake
- 0.7.1 and rails 1.1.2 and I have run ‘rake rails:update’ on both
systems and I have verified that ‘role.rb’ and ‘user.rb’ are the same on
both systems
Clues?
Craig