Exception "TypeError: no implicit conversion of nil into String" when listing files in section
neilabdev opened this issue · 1 comments
neilabdev commented
While trying to use the bcms_kcfinder module in rails 3.2.22.2 and BrowserCMS 3.5.7, I notice it was receiving various errors, which I traced back to an exception cause when trying to list files in a given section. To test, you can run the following in the console:
@section = Cms::Section.last
Cms::ImageBlock.by_section(@section)
Which Returns:
2.3.0 :002 > Cms::ImageBlock.by_section(@section)
Cms::SectionNode Load (0.2ms) SELECT `section_nodes`.* FROM `section_nodes` WHERE `section_nodes`.`node_id` = 3 AND `section_nodes`.`node_type` = 'Cms::Section' LIMIT 1
TypeError: no implicit conversion of nil into String
from /Users/ghost/.rvm/gems/ruby-2.3.0@csp_development/gems/arel-3.0.3/lib/arel.rb:40:in `initialize'
from /Users/ghost/.rvm/gems/ruby-2.3.0@csp_development/gems/arel-3.0.3/lib/arel.rb:40:in `new'
from /Users/ghost/.rvm/gems/ruby-2.3.0@csp_development/gems/arel-3.0.3/lib/arel.rb:40:in `sql'
from /Users/ghost/.rvm/gems/ruby-2.3.0@csp_development/gems/activerecord-3.2.22.2/lib/active_record/associations/join_helper.rb:47:in `block in sanitize'
from /Users/ghost/.rvm/gems/ruby-2.3.0@csp_development/gems/activerecord-3.2.22.2/lib/active_record/associations/join_helper.rb:45:in `map'
from /Users/ghost/.rvm/gems/ruby-2.3.0@csp_development/gems/activerecord-3.2.22.2/lib/active_record/associations/join_helper.rb:45:in `sanitize'
from /Users/ghost/.rvm/gems/ruby-2.3.0@csp_development/gems/activerecord-3.2.22.2/lib/active_record/associations/join_dependency/join_association
The file causing the issue:
#app/assets/models/cms/abstract_file_block.rb
module Cms
class AbstractFileBlock < ActiveRecord::Base
self.table_name = Namespacing.prefix("file_blocks")
validates_presence_of :name
### Error caused Here
scope :by_section, lambda { |section| {
:include => {:attachments => :section_node},
:conditions => ["#{SectionNode.table_name}.ancestry = ?", section.node.ancestry_path]}
}
end
end
neilabdev commented
Turns out to be a bug in ruby when version 2.3.0 and other versions. Version ruby-2.2.3 and ruby-2.0.0-p648 seem to work just fine. Its actually the difference in output of the interolate function when building the query that fails:
# activerecord-3.2.22.2/lib/active_record/associations/join_dependency/join_association.rb
def interpolate(conditions)
if conditions.respond_to?(:to_proc)
instance_eval(&conditions) # this returns nil when the failure occurs, other versions don't fail here.
else
conditions
end
end