Challenge - 5 Problems
Form Helpers Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output HTML of this
form_with helper?Consider this Rails view code:
What HTML does this generate if
form_with(model: @post, local: true) do |form| concat form.label :title concat form.text_field :title concat form.submit 'Save' end
What HTML does this generate if
@post is a new record?Ruby on Rails
form_with(model: @post, local: true) do |form|
concat form.label :title
concat form.text_field :title
concat form.submit 'Save'
endAttempts:
2 left
💡 Hint
Think about what URL and HTTP method Rails uses for new records with
form_with.✗ Incorrect
When
@post is a new record, Rails generates a form that submits to the collection path (e.g., /posts) using POST method to create a new resource.❓ state_output
intermediate2:00remaining
What is the value of the hidden input generated by
form_with for an existing record?Given this code snippet:
If
form_with(model: @post, local: true) do |form| concat form.hidden_field :id end
If
@post.id is 42, what is the value attribute of the hidden input?Ruby on Rails
form_with(model: @post, local: true) do |form| concat form.hidden_field :id end
Attempts:
2 left
💡 Hint
Hidden fields reflect the model's attribute values.
✗ Incorrect
The hidden field for :id will have the value of the model's id attribute, which is 42 here.
📝 Syntax
advanced2:00remaining
Which
form_with syntax correctly disables remote AJAX submission?You want to create a form that submits synchronously (not via AJAX). Which option correctly disables remote submission?
Attempts:
2 left
💡 Hint
Check the official Rails option for disabling remote forms.
✗ Incorrect
The correct option to disable remote AJAX submission is
local: true. The remote option is deprecated.🔧 Debug
advanced2:00remaining
Why does this
form_with raise an error?Given this code:
Why does this raise an error?
form_with(url: posts_path, method: :post) do |form| concat form.text_field :title concat form.submit end
Why does this raise an error?
Ruby on Rails
form_with(url: posts_path, method: :post) do |form| concat form.text_field :title concat form.submit end
Attempts:
2 left
💡 Hint
Think about what
form.text_field needs to generate the input name.✗ Incorrect
When using
form_with with a URL instead of a model, form helpers like text_field need an object or name to generate proper input names. Without a model or scope, it raises an error.🧠 Conceptual
expert3:00remaining
How does
form_with decide the HTTP method for an existing record?When you use
form_with(model: @article) and @article is persisted, which HTTP method does Rails use and why?Attempts:
2 left
💡 Hint
Think about RESTful conventions for updating resources.
✗ Incorrect
Rails uses PATCH method for existing records to update them partially, following RESTful conventions.