Adding class to button_to in Rails not working

360 Views Asked by At

I'm trying to add a class with button_to in Rails, but I keep getting syntax errors. This is what I've got:

<%= button_to "Update this task", user_task_path(current_user, task), method: "patch", remote: true, {class: "update"} %>

I've tried putting various things in and out of braces but I can't get it to work. Any ideas?

1

There are 1 best solutions below

1
SteveTurczyn On

EDIT

Try using form_class (which will assign the class for you)

<%= button_to "Update this task", user_task_path(current_user, task), method: "patch", remote: true, form_class: "update" %>

Failing that, a more long-winded solution...

<%= button_to user_task_path(current_user, task), {method: "patch", remote: true}, {class: "update"} do %>
  Update this task
<% end %>