rails form data not getting saved to db

前端 未结 2 1000
半阙折子戏
半阙折子戏 2021-01-23 05:29

I\'m new to rails and trying to make a simple site to start learning. When I submit my form, however, the data isn\'t saved to the db. I\'m really not sure what\'s wrong, I\'ve

2条回答
  •  后悔当初
    2021-01-23 06:13

    if you are using form_for, use the form_for syntax

    <%= form_for(@calculate) do |form| %>
      <%= form.label :number %>
      <%= form.text_field :number %>
      <%= form.label :root %>
      <%= form.text_field :root %>
      <%= form.submit "Submit" %>
    <% end %>
    

    this will automatically handle the routes if the @calculate is new object it will submit it to create or if it is already saved it will send a put request to edit action

提交回复
热议问题