<% raise Hobo::PermissionDeniedError.new("Not allowed to edit #{this_field}") if !attributes[:disabled] && !can_edit? blank_message ||= ht("#{this_type.name.underscore}.messages.none", :default=>"No #{this_type.model_name.human} available.") limit ||= 100 options ||= begin conditions = ActiveRecord::Associations::BelongsToAssociation.new(this_parent, this_field_reflection).options[:conditions] order = this_field_reflection.klass.default_order this_field_reflection.klass.where(conditions).limit(limit).order(order).select {|x| can_view?(x)} end id_method = this_field_reflection.options[:primary_key] || this_field_reflection.klass.primary_key if text_method.nil? select_options = options.map { |x| [name(:with => x, :no_wrapper => true), x.send(id_method)] } else select_options = options.map do |x| [ text_method.split(".").inject(x) { |v, method| v.send(method) }, x.send(id_method) ] end end select_options = select_options.sort if sort select_options.insert(0, [blank_message, ""]) if include_none || (this.nil? && include_none != false) attributes = add_classes(attributes, "input", "belongs_to", type_and_field) -%>