1

ユーザーがDeviseフォームのBiographyフィールドに入力すると、バッジが授与されるように、DeviseでMerit gemを使用しようとしています。

しかし、私がそれを使用すると、

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

4

2 に答える 2

2

メリットには、Devise コントローラーがインスタンス化しないインスタンス変数が必要です。https://github.com/merit-gem/merit/wiki/How-to-grant-badges-on-user-using-Deviseで説明されているように、そうする必要があります。

于 2013-07-01T09:20:45.130 に答える
0

Devise が数回のキーストロークでユーザー アカウント管理をセットアップするのに優れていることは知っていますが、他の gem や機能と統合するのは困難です。私の経験から、Michael Hartl の例http://ruby.railstutorial.org/ruby-on-rails-tutorial-bookに従うように、ユーザー認証を自分で設定するのに最初に余分な時間を費やす価値があります。User のような Devise の生成されたモデルで Merit を使用すると、明確な問題がありましたが、Hartl を使用した後は問題はありませんでした。

于 2014-03-12T07:21:25.543 に答える