Comments (15)
There's a recent commit in a fork which renames points
to sum_points
inside of model_additions.rb
in jruizes@1f7ceee.
I'll take a look at what's happening, and if it's better I'll rename it to total_points
.
Thanks for your feedback!
from merit.
Meanwhile you may monkey patch ActiveRecord so you can work: http://stackoverflow.com/a/1515571/356060 (valid
is points
in this case).
from merit.
I also tried with the fix for DangerousAtrributeError from the UPDATE notice[1], but did not work for me (the monkey patch method). The environment is Rails 3.1.3.
[1]: If you get an ActiveRecord::DangerousAttributeError: points exception, you may need to temporarily tweak your meritable model, as explained in http://stackoverflow.com/a/1515571/356060.
Thanks for your quick response.
I will try with the fork you mentioned!
from merit.
More: I'll rename the method name as it may collide with ActiveRecord.
Anyway you may need to change that attribute name in your application: http://stackoverflow.com/questions/7718651/activerecorddangerousattributeerror
from merit.
Pretty sure it's coming from your Question
model, monkey patch that one also, and if it works then rename the attribute.
from merit.
I tried the gem 'safe_attributes'
from http://stackoverflow.com/questions/7718651/activerecorddangerousattributeerror and it fixed the problem!
Thanks for your lighting-fast responses!
from merit.
Happy it works for now! :-) But there is a design flaw inside of merit
.
Rails raises ActiveRecord::DangerousAttributeError
if it sees a method on your model is already defined in ActiveRecord::Base
. But merit
is adding many methods to AR::Base
, one being points
. So not only is merit polluting AR::Base
with specific methods, but also It's not allowing client apps to have that common attribute name.
I'll leave this issue open until I rework that. Thanks for the feedback!
from merit.
Understood! Thanks for the great work!
from merit.
Bummer! After adding the safe_attributes gem, there is still a problem when trying to save something over the points attribute:
NameError (undefined local variable or method `sash' for #<Question:0x00000003b9b308>):
app/controllers/admin/games_controller.rb:96:in `block (2 levels) in create'
app/controllers/admin/games_controller.rb:92:in `each'
app/controllers/admin/games_controller.rb:92:in `block in create'
app/controllers/admin/games_controller.rb:69:in `create'
Any idea how to hack the create method to avoid this error?
EDIT: Adding to the Question model:
def points
self[:points]
end
def sash
self.points
end
Seems to fix it. I will continue testing this, maybe more problems can arise from this.
from merit.
Why does a Question need a sash? Is it "meritable"? If not, please paste your rules in a gist.
Anyway sash
should be invisible to the app.
from merit.
It is not "meritable", but somehow when calling Question.points in the create method it asked for it.
from merit.
There's the method names collision, the reason for the exception.
Merit needs to add the points
method only to meritable models instead of to AR::Base
. Relevant code in https://github.com/tute/merit/blob/master/lib/merit/model_additions.rb#L26-52
Maybe I can review it tomorrow or this weekend.
from merit.
Hi @rfernand! Apparently latest commit (4347347) fixes the issue. Could you please try with git's version? If it works fine, I'll release a new minor version.
Thanks!
from merit.
Ok, tested again with the git version of merit and it seems to work fine now.
I removed the code from Question that I had to add before:
# def points
# self[:points]
# end
# def sash
# self.points
# end
And tested create, new, save, question.points. No more annoying problems were found!
Also tested user.points, adding badges/points to user, all with no problems.
Thanks!
from merit.
Awesome, you may use version 1.1.0 now.
Thanks for your help!
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
- Devise & Sign-in then trigger grant_on HOT 12
- On destroy, Integer returned instead of object HOT 10
- 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.