【问题标题】:DEPRECATION WARNING: `#column_for_attribute` will return a null object for non-existent columns in Rails 5. Use `#has_attribute?`弃用警告:`#column_for_attribute` 将为 Rails 5 中不存在的列返回空对象。使用`#has_attribute?`
【发布时间】:2016-12-03 17:43:32
【问题描述】:

我将我的应用程序从 Rails 3.2 迁移到 4.2.6。每当我运行我的应用程序时,都会收到以下警告:

弃用警告:#column_for_attribute 将返回一个空对象 对于 Rails 5 中不存在的列。如果需要,请使用 #has_attribute? 检查属性是否存在。 (从块调用(2 级) 在 _app_views_sessions_new_html_erb__912345678695999592_96040780 中 /home/myuser/Desktop/myproject/app/views/sessions/new.html.erb:12)

这是它在日志中显示的形式,警告在密码行:

<%= semantic_form_for(resource, :as => resource_name, :url => user_session_path, :remote => true, :format => :json}) do |f| %>
      <%= f.inputs do %>
        <%= f.input :email, :label => 'Your email address', :input_html => { :placeholder => "Email"} %>
        <%= f.input :password, :label => 'Your password', :required => true, :input_html => { :placeholder => "Password"} %>
      <% end %>
       <%= f.submit_button :label => 'Sign me in', :button_html => {:class => 'login submit button', :id => 'user_submit' }%>
 <% end %>

请帮忙。

【问题讨论】:

  • 您在使用其他类似设计的东西吗?如果是这样,您可能还需要升级该依赖项。
  • 我正在使用 devise 并将其升级到 4.2.0。
  • 下一步是检查 Devise 是否有未解决的问题。因为这可能是 Rails 5 的警告。

标签: ruby-on-rails


【解决方案1】:

您看到的弃用警告与 Formtastic 有关。 Rails 注意到您的表单中有一些字段(如密码确认字段)与模型中的任何字段都不对应。

这个警告也发生在Formtastic 和 Rails 4.1 和 4.2 之间的 Simple Form 的用户身上,并在特定产品的新版本中得到修复。

同时,这是一个弃用警告,而不是异常,所以尽管它可能很烦人,但它不是一个炫耀。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-03-06
    • 1970-01-01
    • 1970-01-01
    • 2016-11-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多