How do I add an action to a form in React-Rails?

640 views Asked by At

I am building an app with react-rails. I am trying to add multiple forms to a single page by adding custom actions to the controller.

In the past with pure rails I was able to do like so:

<%= form_for @food, :url=>{:controller=>"dailies", :action=>"food_create"}, remote: true, html: { class: "form-horizontal", style: "display:inline;" } do |f| %>

This is how I'm rendering the form:

render: ->
React.DOM.form
  action: '/student/food_create'
  className: 'form-inline'
  onSubmit: @handleSubmit
1

There are 1 answers

0
rmosolgo On

That looks about right. I don't quite understand your question, though.

You might add 2 more props to the React.DOM.form to match the Rails form:

render: ->
  React.DOM.form
    action: "/students/food_create"
    className: "form-inline"
    onSubmit: @handleSubmit 
    "data-remote": true # equal to `remote: true`
    method: "POST"      # or if you want another HTTP verb, put it here