1

I am trying to use Parsley for Rails 4 with Form Tag Helpers.

As said in the documentation

"Options" provide a way for custom attributes; However, Parsley uses the notation "data-parsley". Rails cannot interpret the "-" and application brings out an error.

Is there a workaround?

Thanks,

ughai
  • 9,830
  • 3
  • 29
  • 47
james
  • 515
  • 4
  • 14

1 Answers1

1

There are 2 ways to write data tags in Rails (or other tags with -):

data: {parsley: 'something'} # -> data-parsley="something"

or

'data-parsley' => 'something' # -> data-parsley="something"

Also, there is a strange, but useful behavior: inside data braces, you can use _ and it will renders as -, for ex:

data: {customer_id: 'id'} # -> data-customer-id="id"

The same, as

data: {customer: {id: 'id'}} # -> data-customer-id="id"
Peter Tretyakov
  • 3,380
  • 6
  • 38
  • 54