Hello guys,
I’m dealing with some issue about best practice of how to use Rails
code.
So, what’s the best way to write the following lines that basicaly does
the same thing?
Let’s say we have a link that needs to be a button with some parameters
(theme, size and icon)
- = link_to “Login”, “#”, class: “button”, data: {theme: “green”, size:
“large”, icon: “small-arrow”}
vs. - = link_to “Login”, “#”, class: :button, data: {theme: :green, size:
:large, icon: “small-arrow”}
both of them should generate something like this
Login
Personaly I prefer 1. because when it comes to maintanability is easier:
let’s say that we have to add a second class “login” to this link/button
and to change the theme to “dark-red”
- adding the class: just click after the “n” letter after the word
“button”, hit a space and write the second class “login” - changing the theme: double click on “green” word and write “dark-red”
- adding the class: delete the “:” character, select the word “button”,
wrap it in quotes, add a space and after that the class - changing the theme: select “:green”, add quotes and write the
“dark-red” theme
I find the first version to be more faster to perform than the second
one -> improves mentainability
Other points could be:
- using “:word” notation doesn’t work with spaces and dashes (other
characters), but the “quoted string” notation works - keeping a single way of coding (the one that handles all the cases) ->
more as a standard
So, what do you think? How do you code when you have something like
this?
I would like some opinions about this from some experts in coding Rails.
Thank you very much!