rails form data not getting saved to db

前端 未结 2 999
半阙折子戏
半阙折子戏 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

    0 讨论(0)
  • 2021-01-23 06:28

    Ah hah! I updated my view to:

    <%= form_for @calculate, :url => { :action => "create" } do |f| %>
      <%= f.label :number %>
        <%= f.text_field :number %>
        <%= f.label :root %>
        <%= f.text_field :root %>
        <%= submit_tag("Submit") %>
    <% end %>
    

    And now it works. Awesome.

    0 讨论(0)
提交回复
热议问题