Home How to use Rails link_to to POST to the controller and have an HTML class attribute?
Reply: 0

How to use Rails link_to to POST to the controller and have an HTML class attribute?

user739
1#
user739 Published in May 21, 2018, 10:49 pm

I've looked up the link_to in the Apidock but simply can't get the proper Rails syntax to create the following:

<a href="/benefits/create" class="btn btn-primary">All Changes Complete</a>

I have:

<%= link_to t('view.benefits.all_changes_complete'), { controller: "benefits", action: "create", method: :post }, { class: "btn btn-primary"} %>

The above syntax kind of works, but the method: :post is being added to the href and clicking the link does a GET, resulting in the following:

<a class="btn btn-primary" href="/benefits/create?method=post">All Changes Complete</a>
You need to login account before you can post.

About| Privacy statement| Terms of Service| Advertising| Contact us| Help| Sitemap|
Processed in 0.373612 second(s) , Gzip On .

© 2016 Powered by mzan.com design MATCHINFO