Thanks for the hint.
Looks like the choice of class name school_class is not very good as it causes the has_many :through association to be confused about how to derive the table name. Will fix the name to be schoolclass so we can avoid that part of the problem. /S On Jan 29, 12:11 am, "[email protected]" <[email protected]> wrote: > Hi, > > Rails is complaining about a missing school_class_user association in > School model. > I would recommend to add one: > has_many :school_class_users > > Same might be necessary on the other side of through association. > > -- > Volker > > On 29 Jan., 08:50, Soren <[email protected]> wrote: > > > Progress > > > All my ordinary associations seems to be correct with both direction > > of the associations. > > > I discovered a great tools for debugging and/or > > documentation:http://blog.zmok.net/articles/2006/11/13/visualize-your-rails-schema > > Looks like one could morph this into an association checking tool some > > rainy day. > > > It found a couple of things, but I keep focusing on this set of > > associations: > > belongs_to :first_contact, > > :foreign_key => :first_contact_id, > > :class_name => "User" > > :conditions => "users.role = 'classco'" > > > belongs_to :second_contact, > > :foreign_key => :second_contact_id, > > :class_name => "User" > > :conditions => "users.role = 'classco'" > > > Rather than just two associations to the users model to model the > > various contacts to each class, the right thing to do would be to have > > a has_many :through association. This way I can have as many contacts > > as my users might deem that they need. > > > So I changed this to: > > has_many :contacts, > > :class_name => "User", > > :through => "school_class_user" > > > models/school_class_user.rb contains: > > class SchoolClassUser < ActiveRecord::Base > > > belongs_to :school_class > > belongs_to :user > > > end > > > and models/user.rb has gotten a statement like this as well: > > has_many :school_classes, :through => :school_classes_users > > > There is a database named school_class_user to link to the new model. > > > When I try this code I get this error message from AR: > > > Could not find the association "school_class_user" in model > > SchoolClass > > > I'm sure that I'm doing something wrong but just can not see what - > > can anyone help ? > > > Also - is there something that look bothersome from an AS perspective. > > > /S > > > On Jan 28, 7:39 am, Soren <[email protected]> wrote: > > > > class SchoolClassesController < ApplicationController > > > > layout "default" > > > > before_filter :login_required > > > > #This links to the update_table_config method further down > > > before_filter :update_table_config > > > > # Only list the lowest level that is required to have access > > > # all levels above that is already included > > > > before_filter :cc_required, :except => > > > [:classlist_student, :classlist, :classlist_teachers, :classlist_cc, > > > :list, :update_table, :show, :row, :show_search, :bellschedule, > > > :calendar, :staff, :cc_report, :jobs ] > > > > active_scaffold :school_class do |config| > > > config.columns = > > > [:name, :grade_printable, :sorting_group, :teachers, :ias, > > > :first_contact, :second_contact, :room, :phone] > > > > config.label = "Classes" > > > config.list.sorting = [{ :sorting_group => :asc},{:room => :asc}] > > > config.action_links.add 'classlist', > > > :label => "Class List", > > > :type => :record, > > > :inline => false > > > > config.columns[:grade].label = "internal grade" > > > config.columns[:grade].description = "Set to negative value to > > > remove from class listings" > > > config.columns[:grade_printable].label = "Grade" > > > config.columns[:first_contact].label = "Class Coordinator" > > > config.columns[:second_contact].label = "Class Coordinator" > > > > # This works with staff > > > config.columns[:teachers].label = "Teacher(s)" > > > config.columns[:ias].label = "Instructional Assistant(s)" > > > > config.actions.swap :search, :live_search > > > > list.per_page = 30 > > > > # Add the new report functions to the system > > > if Konfig::KLASS_ALLERGY > > > config.action_links.add 'allergy', > > > :label => "Allergy Report", > > > :type => :record, > > > :inline => false, > > > :security_method => :allergy_authorized? > > > end > > > > # Stripped 5 other functions out - they are almost identical to > > > the one above. > > > > # This logic limits the users listed in the users/list view > > > # Can be used in any controller to control what happens to the > > > records > > > # shown in the List view > > > # Do > > > check:http://wiki.activescaffold.com/wiki/published/Dynamic+conditions_for_... > > > # THIS IS IN SQL SYNTAX !!!!!!!! > > > #['generic IN (?)', ['false']] > > > def conditions_for_collection > > > if !current_user.has_role?('user') > > > [""] > > > else > > > if Konfig::SHOW_GENERIC > > > ['generic = true'] > > > else > > > ['generic = false'] > > > end > > > end > > > end > > > > # Logic to include the generic field in the update editor > > > def update_table_config > > > if not current_user.nil? > > > if current_user.has_role?('user') > > > active_scaffold_config.list.columns.exclude :generic > > > active_scaffold_config.list.columns.exclude :grade_printable > > > active_scaffold_config.list.columns.exclude :grade > > > active_scaffold_config.list.columns.exclude :sorting_group > > > else > > > if current_user.has_role?('admin') > > > active_scaffold_config.update.columns.add :generic > > > active_scaffold_config.create.columns.add :generic > > > active_scaffold_config.list.columns.add :generic > > > active_scaffold_config.list.columns.add :grade_printable > > > active_scaffold_config.update.columns.add :grade_printable > > > active_scaffold_config.create.columns.add :grade_printable > > > active_scaffold_config.list.columns.add :grade > > > active_scaffold_config.update.columns.add :grade > > > active_scaffold_config.create.columns.add :grade > > > active_scaffold_config.list.columns.add :sorting_group > > > active_scaffold_config.update.columns.add :sorting_group > > > active_scaffold_config.create.columns.add :sorting_group > > > else > > > active_scaffold_config.update.columns.exclude :generic > > > active_scaffold_config.list.columns.exclude :generic > > > > active_scaffold_config.update.columns.exclude :grade_printable > > > active_scaffold_config.list.columns.exclude :grade_printable > > > active_scaffold_config.update.columns.exclude :grade > > > active_scaffold_config.list.columns.exclude :grade > > > active_scaffold_config.update.columns.exclude :sorting_group > > > active_scaffold_config.list.columns.exclude :sorting_group > > > end > > > end > > > end > > > end > > > > The association parts from school_classes model is a posted earlier in > > > this thread > > > > /S > > > > On Jan 27, 2:51 am, JSeidel <[email protected]> wrote: > > > > > It's an Active Record method: > > > > From api.rubyonrails.org: > > > > klass() > > > > > Returns the class for the macro. For example, > > > > composed_of :balance, :class_name => ‘Money‘ returns the Money class > > > > and has_many :clients returns the Client class. > > > > > [ hide source ] > > > > > # File vendor/rails/activerecord/lib/active_record/reflection.rb, > > > > line 105 > > > > 105: def klass > > > > 106: @klass ||= class_name.constantize > > > > 107: end > > > > > ...jon > > > > > On Jan 25, 11:29 pm, Soren <[email protected]> wrote: > > > > > > Hi, > > > > > > I have a large fairly complex system and I have ended up with a error > > > > > surrounding the associations between the models. > > > > > > Unfortunately the error message is not very clear to me. Can anyone > > > > > help ? > > > > > > I have a model/controller pair named klass/klasses. Is this a reserved > > > > > word and therefore the source of the problem ? > > > > > > You have a nil object when you didn't expect it! > > > > > The error occurred while evaluating nil.klass > > > > > > RAILS_ROOT: /rails/formdir-dev > > > > > Application Trace | Framework Trace | Full Trace > > > > > > /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/ > > > > > reflection.rb:257:in `source_reflection' > > > > > /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/ > > > > > reflection.rb:257:in `collect' > > > > > /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/ > > > > > reflection.rb:257:in `source_reflection' > > > > > /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/ > > > > > reflection.rb:316:in `derive_class_name' > > > > > /usr/lib64/ruby/gems/1.8/gems/activerecord-2.3.2/lib/active_record/ > > > > > reflection.rb:112:in `class_name' > > > > > /rails/formdir-dev/vendor/plugins/active_scaffold/lib/extensions/ > > > > > reverse_associations.rb:11:in `reverse' > > > > > /rails/formdir-dev/vendor/plugins/active_scaffold/lib/active_scaffold/ > > > > > data_structures/column.rb:117:in `autolink?' > > > > > /rails/formdir-dev/vendor/plugins/active_scaffold/lib/ > > > > > active_scaffold.rb:107:in `links_for_associations' > > > > > /rails/formdir-dev/vendor/plugins/active_scaffold/lib/active_scaffold/ > > > > > data_structures/columns.rb:62:in `each' > > > > > /rails/formdir-dev/vendor/plugins/active_scaffold/lib/active_scaffold/ > > > > > data_structures/columns.rb:62:in `each' > > > > > /rails/formdir-dev/vendor/plugins/active_scaffold/lib/ > > > > > active_scaffold.rb:106:in `links_for_associations' > > > > > /rails/formdir-dev/vendor/plugins/active_scaffold/lib/ > > > > > active_scaffold.rb:59:in `active_scaffold' > > > > > /rails/formdir-dev/app/controllers/users_controller.rb:16 > > > > > /rails/formdir-dev/app/controllers/user_logins_controller.rb:9 -- You received this message because you are subscribed to the Google Groups "ActiveScaffold : Ruby on Rails plugin" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/activescaffold?hl=en.
