I want to create a form in HAML, but I don't have a model or database table. The form should just send its fields via POST
to an action and I will handle it from there.
As far as I could tell, form_for
has to have a record
.
What is the current best practice to do this?
form_for
can also take an arbitrary symbol:
<%= form_for :anything, url: "my_controller/my_action" do |form| %>
<%= form.text_field :name %>
<%= form.submit %>
<% end %>
This will send a post to my_controller/my_action
.
The html output will look something like this:
<form accept-charset="UTF-8" action="my_controller/my_action" method="post">
<input id="anything_name" name="anything[name]" type="text">
<input name="commit" type="submit" value="Save Testing">
</form>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With