【发布时间】:2020-05-14 06:27:57
【问题描述】:
我在我的 rails 应用程序中遇到了这个奇怪的错误
Completed 500 Internal Server Error in 176742ms (ActiveRecord: 148.5ms)
ActionView::Template::Error (Mysql2::Error::ConnectionError: Wrong or unknown protocol: SELECT `lines`.* FROM `lines` WHERE `lines`.`id` = 15 LIMIT 1):
22: <% if defined?(Haml) && respond_to?(:block_is_haml?) && block_is_haml?(block) %>
23: <% capture_haml(day, sorted_events.fetch(day, []), &block) %>
24: <% else %>
25: <% block.call day, sorted_events.fetch(day, []) %>
26: <% end %>
27: <% end %>
28: <% end %>
app/views/presences/index.html.erb:47:in `block (2 levels) in _app_views_presences_index_html_erb__679688437_89682920'
app/views/presences/index.html.erb:7:in `each'
app/views/presences/index.html.erb:7:in `block in _app_views_presences_index_html_erb__679688437_89682920'
app/views/presences/index.html.erb:3:in `_app_views_presences_index_html_erb__679688437_89682920'
app/views/presences/index.html.erb:47:
<th style="background: greenyellow"><%= Line.find(l).name + " bla: " + tmp.size.to_s %></th>
有谁知道如何解决这个问题或知道为什么会出现 mysql 错误?在前面的代码中,我对数组执行了一些选择和检测语句。没有很多mysql查询......而且这个错误只发生在我的测试环境中(不同VM上的生产环境副本)。在我的开发环境中,一切都像魅力一样。
【问题讨论】:
-
看起来您没有“行”表。转到 rails 控制台并确保它。
-
它就在那里。我也可以在任何其他视图中访问它。上面显示的 SQL 查询也适用于我的 SQL 控制台
-
可能在
Line.find(l)中缺少l,有趣的案例从未见过? -
我之前已经使用相同的代码访问了视图行中的
l,只是在另一种情况下它可以工作。如果不是,它会在app/views/presences/index.html.erb:17行抛出错误 -
我能够以不同的方式重构代码以避免该问题。但是现在我的(rufus-)调度程序中有同样的问题。当应用程序开始第一次运行按预期运行时,第二次运行失败并显示 size: SELECT COUNT() FROM
exportsWHEREexports.date= '2020-02-11' config/initializers /scheduler.rb:21 Mysql2::Error::ConnectionError: 错误或未知协议:SELECT COUNT() FROMexportsWHEREexports.date= '2020-02-11' D:/ RubyonRails/Ruby24-x64/lib/ruby/gems/2.4.0/gems/mysql2-0.5.3-x64-mingw32/lib/mysql2/client.rb:131:in `_query'问题?
标签: mysql ruby-on-rails mysql2 actionview