Comments (12)
I think it might be because you use u.user.created_at
on the second grant_on
call, but it should be u.created_at
. Please try it!
You could name the block argument user
to make that clearer:
def initialize
# New user
grant_on 'users/registrations#create', badge: 'New-Baker', model_name: 'User'
# 1 month user
grant_on 'users/sessions#create', badge: "Typical-Baker", model_name: 'User', to: :itself do |user|
user.created_at < "2022-04-25 00:00:00" && user.created_at > "2022-03-01 00:00:00"
end
# 1 year user
grant_on 'users/sessions#create', badge: "Eternal-Baker", model_name: 'User', to: :user do |user|
user.created_at < "2021-05-25 00:00:00"
end
end
from merit.
It could also be that created_at
returns a Time
-like object, whereas "2022-04-25 00:00:00"
is a String
.
If you are on Rails you could use syntax like 1.month.ago
to use comparable data types.
from merit.
Thanks for the response!
I changed up my code quite a bit
routes.rb
devise_for :users, controllers: { registrations: 'registrations', sessions: 'sessions' }
badge_rules.rb
# New user
grant_on 'registrations#create', badge: 'New-Baker', model_name: 'User'
# 1 month user
grant_on 'sessions#create', badge: "Typical-Baker", model_name: 'User', to: :user do |user|
user.created_at < 1.month.ago && user.created_at > 1.year.ago
end
# 1 year user
grant_on 'sessions#create', badge: "Eternal-Baker", model_name: 'User', to: :user do |user|
user.created_at < 1.year.ago
end
Sessions Controller
class SessionsController < Devise::SessionsController
def create
@user = resource # Needed for Merit
super
end
end
Although that did not change or fix anything.
When I log in, I receive this message still [merit] no target_obj found on Rule#applies?
.
Although it works with any other controller like users#show, but I would not prefer a profile to be triggered in order to get a badge. It still seems weird that when logging in, it does not work even when overriding devise sessions itself.
which is custom made to show profiles of that specified user inside of a user controller I made, here is what it looks like:
users_controller.rb
class UsersController < ApplicationController
before_action :authenticate_user!, except: [:show, :index, :followings, :followers]
def show
@user = User.find_by_username(params[:username])
render :show
end
end
from merit.
It's looking better! Now it may be because you don't need to specify , to: :user
in the last two cases. You already get the user
in the block, and adding that option is akin to calling it twice (user.user
). Try that.
I didn't see that yesterday to correct it in my snippet.
from merit.
I removed the to: :user portion but it is still giving me [merit] no target_obj found on Rule#applies?
I removed the to portion:
# New user
grant_on 'registrations#create', badge: 'New-Baker', model_name: 'User'
# 1 month user
grant_on 'sessions#create', badge: "Typical-Baker", model_name: 'User do |user|
user.created_at < 1.month.ago && user.created_at > 1.year.ago
end
# 1 year user
grant_on 'sessions#create', badge: "Eternal-Baker", model_name: 'User' do |user|
user.created_at < 1.year.ago
end
from merit.
I also did more testing.
I called the model_name: 'Resource' and if I put for example resource.present? it will give me the badge after logging in. So I'm thinking something with the controller or model is an issue?
I cant call resource.created_at since that model does not have that attribute.
from merit.
Can I see your whole code somewhere in GitHub so I can further debug? I need to be able to replicate your issue.
from merit.
Yes! I've sent you a invite as it is a private repo.
from merit.
The badges are also meant to display on the profile, so once logging in you can also check the profile for badges or the console after logging for details.
from merit.
I tried debugging but I couldn't make it work in time. This may be a bug in merit.
We'd want to grant to: :action_user
I think, and then we don't need the model_name:
attribute, but ran out of time.
For now, please use add_badge
manually in the controller. Thanks for reporting.
from merit.
Okay, no problem. Thanks for attempting! Let me know if any fix for this
Closing issue now.
from merit.
Hi @serenuy ! We wanted to try out merit in our application. So, was just going through the issues list to see what I should be aware of. Yours was the first one.
For devise sessions controller, the resource is actually a session object and not the user object. users
is just a namespace here. Once the session is created, it'll store :user_id in the sessions_hash which you can use to find out your user and see if it works.
from merit.
Related Issues (20)
- 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
- On destroy, Integer returned instead of object HOT 11
- Urgent Help : Duplicate key entry HOT 2
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.