Comments (14)
Do you have something like:
Badge.create(
:id => 100,
:name => 'autobiographer',
:description => ''
)
in your config/initializer/merit.rb
file? If not, that's why and I'll create a more meaningul error message; if yes, it's a bug.
Thanks for reporting!
from merit.
Added to 'master' a better error message for if the error comes from a not found (not defined) badge, @jodyalbritton.
You may try it with gem 'merit', :git => 'git://github.com/tute/merit.git'
If the error persists, please tell me exactly how may I replicate it.
Best!
from merit.
I tried the version you specified, as well as double checking my config. As you can see points are being granted, but the user is not being found to assign a badge to.
MeritAction Load (0.4ms) SELECT `merit_actions`.* FROM `merit_actions` WHERE `merit_actions`.`processed` = 0
User Load (0.1ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
Sash Load (0.1ms) SELECT `sashes`.* FROM `sashes` WHERE `sashes`.`id` = 2 LIMIT 1
User Load (0.2ms) SELECT `users`.* FROM `users` WHERE `users`.`id` IS NULL LIMIT 1
[merit] no target_obj found on Rule#applies?
BadgesSash Load (0.1ms) SELECT `badges_sashes`.* FROM `badges_sashes` WHERE `badges_sashes`.`sash_id` = 2
CACHE (0.0ms) SELECT `users`.* FROM `users` WHERE `users`.`id` = 1 LIMIT 1
(0.1ms) BEGIN
(0.3ms) UPDATE `users` SET `points` = 150, `updated_at` = '2012-06-11 07:59:51' WHERE `users`.`id` = 1
(30.4ms) COMMIT
(0.1ms) BEGIN
(0.3ms) UPDATE `merit_actions` SET `log` = 'points_granted:10|', `updated_at` = '2012-06-11 07:59:51' WHERE `merit_actions`.`id` = 111
(31.1ms) COMMIT
(0.1ms) BEGIN
(0.3ms) UPDATE `merit_actions` SET `processed` = 1, `updated_at` = '2012-06-11 07:59:51' WHERE `merit_actions`.`id` = 111
(31.5ms) COMMIT
MeritAction Load (0.3ms) SELECT `merit_actions`.* FROM `merit_actions` WHERE `merit_actions`.`id` = 111 LIMIT 1
Completed 302 Found in 454ms (ActiveRecord: 192.5ms)
from merit.
Maybe you already fixed it, but you have a typo in registrationss#create
(an extra 's').
Now I see, you may be using devise. Do you have the registrations controller inside of your app? If not, Devise's controller don't set an instance variable in that controller, you have to set it yourself (for example, with @registration = build_resource
). The target_object is not finding is not the user to be badged, but the object over which the action is applied (could be any entry, in this case it expects @registration
.
I may add a wiki entry for this, or maybe we can come with a better solution for merit.
If you have the controller inside your app please copy it here, if not just override devise's. Thanks for reporting!
from merit.
May we change the issue's title, as the problem seems to have changed?
from merit.
Yes I think the typo was added during the paste, it was not a typo in my code. Second I am using devise, I am not sure I understand about copy the controller. It's fine to change the title.
from merit.
Please try this:
# Rule without ':model_name' option
grant_on ['registrations#create', 'registrations#update'], :badge => 'autobiographer', :temporary => true do |user|
user.name.present? && user.username.present?
end
And add a file app/controllers/users/registrations_controller.rb
:
class Users::RegistrationsController < Devise::RegistrationsController
def create
@registration = build_resource # Needed for Merit
super
end
def update
@registration = resource # Needed for Merit
super
end
end
Merit needs an instance variable called like the singularized controller name, or like the :model_name
option, to save it's id and find the meritable object. If it works correctly we'll add this to the wiki.
from merit.
Without defining a model I get uninitialized constant Registration
from merit.
Sorry, made a mistake, it's with model_name
option:
grant_on ['registrations#create', 'registrations#update'], :badge => 'autobiographer', :model_name => 'User', :temporary => true do |user|
user.name.present? && user.username.present?
end
And add a file app/controllers/users/registrations_controller.rb
:
class Users::RegistrationsController < Devise::RegistrationsController
def create
@user = build_resource # Needed for Merit
super
end
def update
@user = resource # Needed for Merit
super
end
end
from merit.
Seems like progress. I do not get the same error anymore. It still does not grant a badge however.
from merit.
Forgot to tell devise we are overriding it's controllers. In config/routes.rb
(in the devise_for
call):
devise_for :users, :controllers => { :registrations => 'users/registrations' }
from merit.
Okay looks like you solved it! Note the changes I made to the registrations controller class, no User required. Thanks for seeing this through Tute.
Here are my notes.
placed the following in controllers/registrations_controller.rb
class RegistrationsController < Devise:: RegistrationsController
def create
@registration = build_resource # Needed for Merit
super
end
def update
@registration = resource # Needed for Merit
super
end
end
Placed the following in routes.rb
devise_for :users, :controllers => { :registrations => 'registrations' }
Placed the following in models/merit/badge_rules.rb
grant_on ['registrations#create', 'registrations#update'], :badge => 'autobiographer', :model_name => 'User' do |user|
user.username.length > 2
end
placed the following in initializers/merit.rb
Badge.create!({
:id => 1,
:name => 'autobiographer'
})
from merit.
Nice, thank you for the feedback! If you want to add it to the wiki just do it, if not I'll do it in a little while.
from merit.
Wrapped up in https://github.com/tute/merit/wiki/How-to-grant-badges-on-user-registration-using-Devise
from merit.
Related Issues (20)
- Add/Subtract points: NO Method error HOT 8
- undefined method 'create' for Merit:Action:Class HOT 12
- Use DeviseInvitable with Merit HOT 2
- Display flash messages to notify users when they obtain badges/points HOT 9
- Adding points doesn't work the first time HOT 1
- Display a specific badge and the users who obtained it HOT 2
- Merit 4.0 causing Heroku deployment errors HOT 4
- Typo in active_record/merit_generator task
- Deprecation warning: Expected string default value for '--orm'; got false (boolean). HOT 3
- Granting badges with Devise Registrations#update not working HOT 11
- rails g merit:install don't generating migrations on Rails6 HOT 18
- can't write unknown attribute `sash_id` when calling points method on user HOT 3
- subtract_points is not working HOT 3
- Missing index on merit_actions table for processed HOT 2
- Error on create merit_actions migration file HOT 2
- Score on namespaced/controller#action, can not trigger Merit::Action HOT 6
- Error every time code changes HOT 7
- do not support grape? HOT 1
- Devise & Sign-in then trigger grant_on HOT 12
- On destroy, Integer returned instead of object HOT 11
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from merit.