我遇到了一个一周都无法自己解决的问题——我很绝望。
我有一个带有 Trailblazer 的 Rails 5.2 项目。在应用程序的一个地方,我发现了这个错误:
TypeError - no implicit conversion of Symbol into Hash:
app/concepts/post/admin/views/_authors_tab.slim:10:in `block (2 levels) in singleton class'
app/concepts/post/admin/views/_authors_tab.slim:9:in `block in singleton class'
app/concepts/post/admin/views/_authors_tab.slim:65534:in `singleton class'
app/concepts/post/admin/views/_authors_tab.slim:65531:in `__tilt_70096639860360'
app/concepts/post/admin/views/show.slim:14:in `block in singleton class'
app/concepts/post/admin/views/show.slim:65534:in `singleton class'
app/concepts/post/admin/views/show.slim:65531:in `__tilt_70096639860360'
app/concepts/post/admin/cell.rb:13:in `show'
app/views/admin/posts/show.slim:3:in `_app_views_admin_posts_show_slim__1322321696587881215_70096664842560'
app/controllers/application_controller.rb:71:in `apply_time_zone'
Started POST "/__better_errors/51d28299c14c669d/variables" for ::1 at 2018-10-22 15:00:18 +0300
_authors_tab.slim:10(9 和 10 行):
- authors.each do |author|
= concept 'post/author/list_item/cell', author, context: :admin
下面是我专门为最好的演示而剪下的代码(当然,错误被保留了):
class Post::Author::ListItem::Cell < RBlog::Cell
option_property :context, nil_check: true
def show
render
end
end
这是一个包含未知方法描述的文件 ( app/concepts/r_blog/cell/option_property.rb ):
module RBlor::Cell::OptionProperty
def option_property(name, nil_check: false)
if nil_check
define_method(name) do
raise "Option #{name} cannot be blank" if @options[name].nil?
@options[name]
end
else
define_method(name) { @options[name] }
end
private name
end
end
至于show.slim
上面代码中的文件——我评论了它的所有内容,删除了它,甚至保持原样(使用 中描述的方法Post :: Author :: ListItem :: Cell
,但正如我上面写的那样被删除了)——这个文件不会影响任何东西。显然错误在处理之前就出现了。
可能是什么问题呢