0
當我嘗試使用煉油CMS時,我得到一個未定義的方法`validators_on'for NilClass:Class error。煉油廠CMS undefined方法`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」的折舊?我找不到這方面的任何證據。