GithubHelp home page GithubHelp logo

Comments (15)

tute avatar tute commented on July 18, 2024

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.

tute avatar tute commented on July 18, 2024

Meanwhile you may monkey patch ActiveRecord so you can work: http://stackoverflow.com/a/1515571/356060 (valid is points in this case).

from merit.

rfernand avatar rfernand commented on July 18, 2024

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.

tute avatar tute commented on July 18, 2024

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.

tute avatar tute commented on July 18, 2024

Pretty sure it's coming from your Question model, monkey patch that one also, and if it works then rename the attribute.

from merit.

rfernand avatar rfernand commented on July 18, 2024

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.

tute avatar tute commented on July 18, 2024

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.

rfernand avatar rfernand commented on July 18, 2024

Understood! Thanks for the great work!

from merit.

rfernand avatar rfernand commented on July 18, 2024

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.

tute avatar tute commented on July 18, 2024

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.

rfernand avatar rfernand commented on July 18, 2024

It is not "meritable", but somehow when calling Question.points in the create method it asked for it.

from merit.

tute avatar tute commented on July 18, 2024

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.

tute avatar tute commented on July 18, 2024

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.

rfernand avatar rfernand commented on July 18, 2024

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.

tute avatar tute commented on July 18, 2024

Awesome, you may use version 1.1.0 now.
Thanks for your help!

from merit.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.