0
0
Ruby on Railsframework~10 mins

Form helpers (form_with) in Ruby on Rails - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to create a form using form_with for a new @post object.

Ruby on Rails
<%= form_with model: [1] do |form| %>
  <%= form.text_field :title %>
  <%= form.submit %>
<% end %>
Drag options to blanks, or click blank then click option'
APost.new
Bpost
C@post
Dposts_path
Attempts:
3 left
💡 Hint
Common Mistakes
Using the class name instead of the instance variable.
Using the symbol or string instead of the model object.
2fill in blank
medium

Complete the code to create a form that submits to the posts_path URL with method POST.

Ruby on Rails
<%= form_with url: [1], method: :post do |form| %>
  <%= form.text_field :content %>
  <%= form.submit 'Create' %>
<% end %>
Drag options to blanks, or click blank then click option'
Aposts_path
Bnew_post_path
Cedit_post_path
Dpost_path
Attempts:
3 left
💡 Hint
Common Mistakes
Using singular path helpers which expect an ID.
Using the new or edit path helpers which are for GET requests.
3fill in blank
hard

Fix the error in the form helper by completing the missing option to disable local submission (use AJAX).

Ruby on Rails
<%= form_with model: @comment, [1]: false do |form| %>
  <%= form.text_area :body %>
  <%= form.submit %>
<% end %>
Drag options to blanks, or click blank then click option'
Alocal
Bremote
Cajax
Dasync
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'remote' instead of 'local' option.
Using non-existent options like 'ajax' or 'async'.
4fill in blank
hard

Fill both blanks to create a form with a text field for name and a submit button labeled 'Save'.

Ruby on Rails
<%= form_with model: @user do |form| %>
  <%= form.[1] :name %>
  <%= form.[2] 'Save' %>
<% end %>
Drag options to blanks, or click blank then click option'
Atext_field
Bsubmit
Ctext_area
Dbutton
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'text_area' instead of 'text_field' for single line input.
Using 'button' instead of 'submit' for the submit button.
5fill in blank
hard

Fill all three blanks to create a form that uses form_with with a model, disables local submission, and includes a password field.

Ruby on Rails
<%= form_with model: [1], [2]: false do |form| %>
  <%= form.[3] :password %>
  <%= form.submit 'Login' %>
<% end %>
Drag options to blanks, or click blank then click option'
A@user
Blocal
Cpassword_field
Dremote
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'remote' instead of 'local' for the option name.
Using 'text_field' instead of 'password_field' for password input.