我正在尝试将 Merit gem 与 Devise 一起使用,这样如果用户在 Devise 表单中填写 Biography 字段,那么他们将获得徽章。
但是,当我使用它时,它说
undefined method `biography' for true:TrueClass
这是给我错误的部分:
/models/merit/badge_rules.rb
grant_on 'registrations#update', badge: 'autobiographer', temporary: true do |user|
user.biography.present?
end
为什么它认为用户属于 TrueClass?
/views/devise/registrations/edit.html.erb
<h2>Edit <%= resource_name.to_s.humanize %></h2>
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name), :html => { :method => :put, :class => 'form-vertical' }) do |f| %>
<%= f.error_notification %>
<%= display_base_errors resource %>
<%= f.input :first_name, :required => true, :autofocus => true %>
<%= f.input :last_name, :required => true %>
<%= f.input :username, :required => true %>
<%= f.input :email, :required => true %>
<%= f.input :biography %>
<%= f.input :password, :autocomplete => "off", :hint => "leave it blank if you don't want to change it", :required => false %>
<%= f.input :password_confirmation, :required => false %>
<%= f.input :current_password, :hint => "we need your current password to confirm your changes", :required => true %>
<%= f.button :submit, 'Update', :class => 'btn-primary' %>
<% end %>
<h3>Cancel my account</h3>
<p>Unhappy? <%= link_to "Cancel my account", registration_path(resource_name), :data => { :confirm => "Are you sure?" }, :method => :delete %>.</p>
<%= link_to "Back", :back %>
优点.rb
# Create application badges (uses https://github.com/norman/ambry)
badges = [
{id: 1,name: 'just-registered',image:"/images/registered.png",custom_fields:"Registered for an account"},
{id: 2,name: 'verified-user',image:"/images/verified-user.png",custom_fields:"Verified as a valid user" },
{id: 3,name: 'first-image',image:"/images/registered.png",custom_fields:"Uploaded first profile picture"},
{id: 4,name: 'first_vote',image:"/images/vote.png",custom_fields:"Voted for your first professor"},
{id: 5,name: 'autobiographer',image:"/images/biography.png",custom_fields:"Wrote a biography about yourself."}
]
badges.each do |badge|
Merit::Badge.create!(badge)
end