Rails 6 - 调用不正确的助手
Rails 6 - Calling incorrect helper
今天我的应用程序开始调用错误命名的助手。
加载 Drills
模型的视图时,会调用 Exercise
模型助手。这从今天开始发生,没有任何改变。
例如,当我加载 Drills
的显示视图时:
Rendering drills/show.html.erb within layouts/application
Rendered drills/show.html.erb within layouts/application (Duration: 3.5ms | Allocations: 1551)
Completed 500 Internal Server Error in 63ms (ActiveRecord: 2.8ms | Allocations: 6965)
ActionView::Template::Error (undefined method `created_at' for nil:NilClass):
3: <div class="flex justify-between items-center mb-4">
4: <h1 class="h3"><%= link_to 'Drills', drills_path %> > Drill on <%= @drill.date_held.strftime('%d/%b/%y') %></h1>
5: <%= link_to 'Download PDF', drill_path(@drill, :pdf), class: "btn btn-link" %>
6: <% if can_edit? %><%= link_to 'Edit', edit_drill_path(@drill), class: "btn btn-link" %><% end %>
7: <% if can_destroy? %><%= link_to 'Delete', drill_path, class: "btn btn-danger outline", method: :delete, data: { remote: true, confirm: "Are you sure?" } %> <% end%>
8: </div>
9:
app/helpers/exercises_helper.rb:6:in `can_edit?'
app/views/drills/show.html.erb:6
调用了错误的控制器?这是如何解决的?
查看有关 Rails 助手的文档:https://api.rubyonrails.org/classes/ActionController/Helpers.html
In addition to using the standard template helpers provided, creating custom helpers to extract complicated logic or reusable functionality is strongly encouraged. By default, each controller will include all helpers. These helpers are only accessible on the controller through #helpers
您的 exercises_helper.rb
中似乎已经有一个名为 can_edit?
的方法。
如果您只需要 Drill
Drill
controller/views 中的助手,那么您必须遵循以下步骤:
To return old behavior set config.action_controller.include_all_helpers to false.
今天我的应用程序开始调用错误命名的助手。
加载 Drills
模型的视图时,会调用 Exercise
模型助手。这从今天开始发生,没有任何改变。
例如,当我加载 Drills
的显示视图时:
Rendering drills/show.html.erb within layouts/application
Rendered drills/show.html.erb within layouts/application (Duration: 3.5ms | Allocations: 1551)
Completed 500 Internal Server Error in 63ms (ActiveRecord: 2.8ms | Allocations: 6965)
ActionView::Template::Error (undefined method `created_at' for nil:NilClass):
3: <div class="flex justify-between items-center mb-4">
4: <h1 class="h3"><%= link_to 'Drills', drills_path %> > Drill on <%= @drill.date_held.strftime('%d/%b/%y') %></h1>
5: <%= link_to 'Download PDF', drill_path(@drill, :pdf), class: "btn btn-link" %>
6: <% if can_edit? %><%= link_to 'Edit', edit_drill_path(@drill), class: "btn btn-link" %><% end %>
7: <% if can_destroy? %><%= link_to 'Delete', drill_path, class: "btn btn-danger outline", method: :delete, data: { remote: true, confirm: "Are you sure?" } %> <% end%>
8: </div>
9:
app/helpers/exercises_helper.rb:6:in `can_edit?'
app/views/drills/show.html.erb:6
调用了错误的控制器?这是如何解决的?
查看有关 Rails 助手的文档:https://api.rubyonrails.org/classes/ActionController/Helpers.html
In addition to using the standard template helpers provided, creating custom helpers to extract complicated logic or reusable functionality is strongly encouraged. By default, each controller will include all helpers. These helpers are only accessible on the controller through #helpers
您的 exercises_helper.rb
中似乎已经有一个名为 can_edit?
的方法。
如果您只需要 Drill
Drill
controller/views 中的助手,那么您必须遵循以下步骤:
To return old behavior set config.action_controller.include_all_helpers to false.