炼油厂CMS未定义方法`validators_on'

时间:2014-10-01 09:14:02

标签: ruby-on-rails heroku ruby-on-rails-3.2 refinerycms

我为NilClass获取了一个未定义的方法`validators_on':当我尝试使用Refinery CMS时出现类错误。

代码块是:

  class ActionView::Helpers::FormBuilder
  alias :orig_label :label

  # add a '*' after the field label if the field is required - Added in the password field label
  def label(method, content_or_options = nil, options = nil, &block)
    if content_or_options && content_or_options.class == Hash
      options = content_or_options
    else
      content = content_or_options
    end

    required_mark = ''
    required_mark = ' *'.html_safe if object.class.validators_on(method).map(&:class).include? ActiveModel::Validations::PresenceValidator

    content ||= method.to_s.humanize
    content = content + required_mark

    self.orig_label(method, content, options || {}, &block)
  end
end

我相信当我在视图中添加它时,它不会得到“*”。请参阅视图代码:

    <div class="inner">
      <div class="registration">
        <ul>
          <% @user.errors.full_messages.each do |error| %>
            <li><%= error %></li>
          <% end %>
        </ul>
        <form action="/sign-up" method="POST" accept-charset="utf-8">

          <label for="user[email]">Email</label>
          <input type="text" name="user[email]" value="<%= @user.email %>" id="user[email]">

          <label for="user[password]">Password *</label>
          <input type="password" name="user[password]" value="" id="user[password]">

          <label for="user[password_confirmation]">Password Confirmation</label>
          <input type="password" name="user[password_confirmation]" value="" id="user[password_confirmation]">

          <p><input type="submit" class='btn' value="Sign Up"></p>
        </form>
      </div>
    </div>

从我可以看出,当呈现此页面时,该方法不会读取“*”。什么会导致这个?

另一个奇怪的事情是,当我在heroku上运行此代码时,我没有任何问题。但是当我尝试在我的本地机器上运行或九倍时,它会中断。 ruby 1.9.1和1.9.3之间是否存在“validations_on”的折旧?我找不到任何证据。

1 个答案:

答案 0 :(得分:0)

对于这个版本的应用程序,我必须填充数据库才能使任何工作。