如何在React-Rails中向表单添加操作?

时间:2015-06-20 02:14:38

标签: ruby-on-rails reactjs react-rails

我正在使用react-rails构建应用程序。我试图通过向控制器添加自定义操作将多个表单添加到单个页面。

过去使用纯轨道我可以这样做:

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

这就是我渲染表单的方式:

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

1 个答案:

答案 0 :(得分:0)

看起来是正确的。不过,我不太明白你的问题。

您可以向React.DOM.form添加2个道具以匹配Rails表单:

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