Challenge - 5 Problems
Form_with Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediateWhat is the output HTML of this
form_with helper?Given the following Rails code, what is the rendered HTML form's
action attribute value?Ruby on Rails
form_with model: @article, local: true do |form| form.text_field :title end
Attempts:
2 left
💡 Hint
Think about what URL Rails uses for a new record when using
form_with with a model.✗ Incorrect
When @article is a new record, form_with generates a form with action="/articles" for creating a new article.
❓ state_output
intermediateWhat is the value of the
method attribute in this form?Consider this Rails code snippet. What HTTP method will the form use when submitted?
Ruby on Rails
form_with model: @user, url: user_path(@user), local: true do |form| form.password_field :password end
Attempts:
2 left
💡 Hint
Check if the model is a persisted record and what Rails uses for updates.
✗ Incorrect
If @user is persisted, form_with uses patch as the HTTP method for updates.
📝 Syntax
advancedWhich option correctly uses
form_with to submit data asynchronously?Select the code snippet that creates a form submitting data via AJAX using
form_with.Attempts:
2 left
💡 Hint
Rails uses a specific option to enable AJAX submission in
form_with.✗ Incorrect
The remote: true option tells Rails to submit the form via AJAX.
🔧 Debug
advancedWhy does this
form_with not generate the expected input name attribute?Given this code, the generated input's name attribute is just "title" instead of "article[title]". What is the cause?
Ruby on Rails
form_with do |form| form.text_field :title end
Attempts:
2 left
💡 Hint
Think about how
form_with generates input names when no model is given.✗ Incorrect
Without a model: option, form_with treats the form as non-model-bound, generating input names without namespacing.
🧠 Conceptual
expertWhat is the main difference between
form_with and form_for in Rails 7?Choose the statement that best explains the key conceptual difference between
form_with and form_for.Attempts:
2 left
💡 Hint
Think about Rails 7's approach to form helpers and their evolution.
✗ Incorrect
Rails 7 introduced form_with to unify the previous helpers form_for and form_tag into one consistent API that supports both model-bound and generic forms.
