Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

hyphen in API params

The answer to this question specifically mentions using the params [:body-plain]. However, Rails throws this error: NameError (undefined local variable or method 'plain' for #<IncomingMailsController:0x0000000913f278>):

How can I access params that have a hyphen in? I can't change the params as they're posted from a third party API (Mailgun).

like image 419
snowangel Avatar asked Dec 20 '22 18:12

snowangel


1 Answers

You need to access them like this:

params[:'body-plain']

Or even just like this:

params["body-plain"]

You have to escape your symbol name if it contains special characters.

like image 96
Maurício Linhares Avatar answered Dec 31 '22 09:12

Maurício Linhares