Complete the code to create a form that submits data in Rails.
<%= form_with url: '/submit', method: '[1]' do %> <%= label_tag :name %> <%= text_field_tag :name %> <%= submit_tag 'Send' %> <% end %>
Forms that send data usually use the POST method to submit user input securely.
Complete the code to add a text input field named 'email' inside the form.
<%= form_with url: '/subscribe', method: 'post' do %> <%= label_tag :email %> <%= [1] %> <%= submit_tag 'Subscribe' %> <% end %>
The text_field_tag creates a simple text input for the email.
Fix the error in the form helper to correctly create a form for a @user object.
<%= form_with model: [1] do |form| %> <%= form.label :username %> <%= form.text_field :username %> <%= form.submit 'Save' %> <% end %>
The form_with helper expects an instance variable like @user to bind the form to the model object.
Fill both blanks to create a form that submits to the 'create' action with POST method and includes a hidden authenticity token.
<%= form_with url: [1], method: [2] do %> <%= hidden_field_tag :authenticity_token, form_authenticity_token %> <%= submit_tag 'Submit' %> <% end %>
The form submits to '/users' with POST method to create a new user, and the authenticity token protects against CSRF attacks.
Fill all three blanks to build a form that edits a @post object, uses PATCH method, and includes a text area for content.
<%= form_with model: [1], method: [2] do |form| %> <%= form.label :content %> <%= form.[3] :content %> <%= form.submit 'Update' %> <% end %>
The form edits the @post object using PATCH method and includes a text area for the content field.