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_collection
# 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.