DEV Community

Cover image for Your first ruby gem 💎

Your first ruby gem 💎

Louis Sommer on June 20, 2021

I remember reading many times over this piece of advice given to new, aspiring developers : « Go ahead! Read some source code, then contribute to o...
Collapse
 
romanvanloo profile image
RomanVanLoo

Great article, but how do you differentiate your gem from the already pretty famous "Cocoon"?

Collapse
 
siarhei_siniak_marketing profile image
Siarhei Siniak
  1. links 1.1. github.com/nathanvda/cocoon/issues (3k on github) github.com/nathanvda/cocoon/issues... github.com/dabroz/cocoon-js-vanilla 1.3. stimulus.hotwire.dev/reference/con... turbo.hotwire.dev/reference/drive github.com/hotwired/stimulus (10.5k on github)
  2. it's cool that you've written a simple version of cocoon and are capable of customizing few aspects of it, like say replacing jquery with stimulus, etc. Has it come due to a difficulty of sending PRs into an existing code base?
Collapse
 
lso profile image
Louis Sommer

In all honesty, we didn't feel like doing so. Neither of us ever liked working with cocoon but still did because it was the only available tool to help with the issue at hand. I think contributing to an existing codebase makes sense for projects you love and wish to support and enhance, but here we really wanted to start from scratch with a completely different approach.
That being said, it's one of our main references for this project, and it helped us tremendously in writing some parts of the gem. Like I said, learn from the best ; (the missing part was "Then, try and make it better !" 🤓)

Collapse
 
lso profile image
Louis Sommer • Edited

Hey Roman ! Thanks ! Our take on the issue is quite different from cocoon. We're providing users with a complete wrapper around nested_attributes, which includes :

  • Easy configuration and syntax in the model
  • Easier permission of attributes in the controller
  • Either a preconfigured one-liner, or a very flexible way of displaying fields on the view side (without having to resort to quirky and unreliable data attributes)
  • Generators, including one that generates all the above config + a pre-filled partial. Also, cocoon is implemented in jquery, whereas we chose to implement everything with stimulus. Have a look at the doc for more details 😬
Collapse
 
romanvanloo profile image
RomanVanLoo

Alright cool! I definitely try it out next time in need for nested forms! ✌️
Cool to use stimulus, it's definitely an underrated framework!

Collapse
 
alexandreruban profile image
Alexandre Ruban

Excellent article Louis and Romain!
It's great that you shared the whole process, from the pain to the release while still describing all the code challenges you had to solve ✨

Congrats on this new gem!

Collapse
 
trandthanh profile image
Thanh TRAN

Incredible article! Thanks for taking us on your journey and for sharing the way you came about this gem. Love the "let's do it and make it" attitude. ​

I agree, DevX is so important.

Can't wait to start using it and to see more people adopt the gem. Congrats to both of you!

Collapse
 
lewiscowles1986 profile image
Lewis Cowles

Very cool. Did you consider a task like rails ships with, which detects yarn and runs? It's built into rails 6 I think, so is an official rails friendly pattern as far as I'm concerned.

Collapse
 
lso profile image
Louis Sommer

Thanks Lewis ! That's good to know ; do you think it would be appropriate to use this pattern for the whole javascript part of the gem ?

Collapse
 
lewiscowles1986 profile image
Lewis Cowles

Hey Louis,

I was thinking just for initial installation.

Not sure what you meant though. Sorry for slow reply.

Really enjoyed reading.

Collapse
 
elieslama profile image
Élie Slama

Excellent ! I wish more guides were as well written as this :)

Collapse
 
tmpou1 profile image
Thomas P

Congrats to you Romain and Louis! Both for the gem and for the description of your journey in this article!

Collapse
 
ericlecodeur profile image
Eric Le Codeur

High quality post, thanks!

Collapse
 
sebcoppo profile image
Sebastien

Excellent ! Amazing job! Thanks for sharing👍