DEV Community

Discussion on: Let's Use Rails Partials To Render Art from Magic: the Gathering!

Collapse
 
isalevine profile image
Isa Levine • Edited

These are both excellent pieces of advice, thank you Andrew! I did incorporate the ||= bit (is there a name for that??) into the most recent refactor, and am on the lookout for other places to use it in my code. I gave you a shoutout at the bottom of my followup article where I used it, let me know if you want me to change it/remove it/link to something else of yours: dev.to/isalevine/using-rails-servi...

I'll definitely be referring back to your point about the simpler syntax for partials the next time I'm working with them too! I definitely like to be as overly-verbose and non-shortcut-y as possible at the start, but no question the shortened syntax looks better and more readable. :)

Collapse
 
andrewbrown profile image
Andrew Brown 🇨🇦

I like to be as overly-verbose and non-shortcut-y as possible at the start

👍👍👍

Thread Thread
 
isalevine profile image
Isa Levine • Edited

Also, this is interesting--I was refactoring to shorten-ify-icate the partials syntax, but apparently removing the partial: bit screws up how the collection: foo , as: :bar syntax.

So, this:

<%= render '/pages/cards/card', collection: session[:img_array], as: :img_hash %>

led to this:
screenshot of Rails error, saying :img_hash is undefined

Any idea why collection: isn't iterating through session[:img_array] and repeatedly passing each img_hash without the partial: explicitly there?

Thread Thread
 
andrewbrown profile image
Andrew Brown 🇨🇦

With collection, I supposed short form doesn't work since the logic is too difficult.

So I guess short form only works for non-collection partials