我正在使用脚手架创建的默认代码。我没有改变任何东西。
Showing app/views/presences/_form.html.erb where line #1 raised:
undefined method `model_name' for NilClass:Class
1: <%= form_for(@presence) do |f| %>
2: <% if @presence.errors.any? %>
3: <div id="error_explanation">
4: <h2><%= pluralize(@presence.errors.count, "error") %> prohibited this presence from being saved:</h2>
这里出了什么问题?我从不调用名为“model_name”的方法,并且此代码是自动化的,那么为什么它不起作用?
谢谢
最佳答案
尝试将其添加到 new
中的 presences_controller
或呈现表单的其他相关操作中:
#presuming your model is called Presence
@presence = Presence.new
关于ruby-on-rails - 未定义方法 model_name,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6430426/