Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Different Types of Badges #28

Closed
zackyap opened this issue Oct 8, 2012 · 7 comments
Closed

Different Types of Badges #28

zackyap opened this issue Oct 8, 2012 · 7 comments

Comments

@zackyap
Copy link

zackyap commented Oct 8, 2012

My project needed different types of badges like Foursquare's: Foursquare, Expertise and Partner badges. Some would have levels, some would not. It's probably a matter of adding a field called type to the Badge model.

Is there a better way of adding fields to the model other than having them coded into the gem? Not too sure about the ambry gem but could it be possible to extend the Badge class and just add the fields there?

@tute
Copy link
Member

tute commented Oct 9, 2012

Interesting question. Tried subclassing Badge for adding the Ambry field but couldn't make it work:

require 'ambry'
require 'ambry/active_model'

class MyAppBadge < Badge
  extend Ambry::Model
  extend Ambry::ActiveModel

  field :type
end
Badge.new.attributes # => {"id"=>nil, "name"=>nil, "level"=>nil, "image"=>nil, "description"=>nil} 
MyAppBadge.new.attributes # => {"type"=>nil} 

@norman, do you think an Ambry model should be extendable like this?

@tute
Copy link
Member

tute commented Oct 9, 2012

Meanwhile, this seems to work:

require 'ambry'
require 'ambry/active_model'

class MyAppBadge < Badge
  extend Ambry::Model
  extend Ambry::ActiveModel

  field *Badge.new.attributes.keys, :type
end
Badge.new.attributes.keys # => {"id"=>nil, "name"=>nil, "level"=>nil, "image"=>nil, "description"=>nil} 
MyAppBadge.new.attributes # => {"id"=>nil, "name"=>nil, "level"=>nil, "image"=>nil, "description"=>nil, "type"=>nil} 

@zackyap
Copy link
Author

zackyap commented Oct 9, 2012

This makes sense. Thanks for trying it out.
I'll try it out too but if there's a better way, I think it'd help open up a few possibilities in terms of what badges can do depending on app design.

@tute
Copy link
Member

tute commented Nov 20, 2012

ambry closed the related issue, with a nice code example and explanation on why do they prefer inclusion of modules to solve an issue like this, instead of subclassing. It works elegantly, and you can find it in: norman/ambry#13 (comment)

Thanks for your feedback!

@tute tute closed this as completed Nov 20, 2012
@Shpigford
Copy link

Would this be the way to group/indicate badges that are harder to get?

For instance, Stack Overflow's badge system has Gold, Silver and Bronze badges. Gold are rare and require quite a bit more work to get and Bronze are the easiest.

@tute
Copy link
Member

tute commented Feb 7, 2013

If you don't use the :level badge option for anything else, it applies for this problem.

@tute
Copy link
Member

tute commented Apr 30, 2013

Now fixed in merit master as of 97c998f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants