Practice - 5 Tasks
Answer the questions below
1fill in blank
easyComplete 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'
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.
✗ Incorrect
The
form_with helper uses the model object @post to build the form for that record.2fill in blank
mediumComplete 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'
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.
✗ Incorrect
The
posts_path is the correct URL helper for creating a new post with POST method.3fill in blank
hardFix 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'
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'remote' instead of 'local' option.
Using non-existent options like 'ajax' or 'async'.
✗ Incorrect
The option
local: false disables local submission and enables AJAX.4fill in blank
hardFill 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'
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.
✗ Incorrect
Use
text_field for the input and submit for the button with label.5fill in blank
hardFill 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'
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.
✗ Incorrect
Use the model instance
@user, set local: false to enable AJAX, and use password_field for password input.