0

I'm comparing some Rails link_to tags.

In one place (where an admin can delete a user account), a template has:

link_to "Delete", user, method: :delete

In another place (where someone can log out, deleting a session), a different template has:

link_to "Log out", logout_path, method: "delete"

I've tried both :delete and "delete" in both places, and the code seems to work the same in all configurations. So...is the syntax interchangeable? If so, is one preferable? I notice that in the docs, the symbol form is discussed and shown, but the quotation mark form is used once as well.

Note, this isn't just a question whether to use symbol or string arguments or keys, I think. I understand that. It's about the particular inconsistent usage spotted with regard to this particular method.

Sorry if this is a noob question.

globewalldesk
  • 544
  • 1
  • 3
  • 18
  • Possible duplicate of [When to use symbols instead of strings in Ruby?](https://stackoverflow.com/questions/16621073/when-to-use-symbols-instead-of-strings-in-ruby) – Simple Lime Aug 19 '17 at 02:57
  • No, it's not a duplicate of that question. If you think my question is answered there, I'd be fascinated to learn how. Maybe your point is that there's no more that could be said about this particular method and how it uses symbols vs strings than can be found there? Then I guess the answer to me is "nope, it doesn't matter, except for this wrinkle you might want to look at." – globewalldesk Aug 20 '17 at 04:34

1 Answers1

0

@simple-lime has already posted a good anwser for the use case for symbol and string. Symbol is better to use for ruby >= 2.2. But I would say that it also depends on your current codebase, if too many places using string just use it, should keep your code consistent.

Tai
  • 1,244
  • 9
  • 11
  • No, this isn't my question. My question concerns the Rails `link_to` method and whether it matters that Hartl and others seem to use both kind of arguments. – globewalldesk Aug 20 '17 at 04:29