【问题标题】:Refinery CMS undefined method `validators_on'炼油厂 CMS 未定义方法“validators_on”
【发布时间】:2014-10-01 09:14:02
【问题描述】:

当我尝试使用 Refinery CMS 时,我得到 NilClass:Class 错误的未定义方法 `validators_on'。

代码块是:

  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”折旧?我找不到任何证据。

【问题讨论】:

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


    【解决方案1】:

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2014-05-04
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多