Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rails 4 form without model and database

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?

like image 449
jbehrens94 Avatar asked Oct 26 '15 15:10

jbehrens94


Video Answer


1 Answers

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>
like image 132
Josh Avatar answered Feb 09 '23 06:02

Josh