Challenge - 5 Problems
Rails Link & URL Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
❓ component_behavior
intermediate2:00remaining
What is the output of this Rails link_to helper?
Consider the following code in a Rails view:
What HTML does this generate?
link_to 'Profile', user_path(42), class: 'btn'
What HTML does this generate?
Ruby on Rails
link_to 'Profile', user_path(42), class: 'btn'
Attempts:
2 left
💡 Hint
Remember that user_path(42) generates the URL for user with id 42.
✗ Incorrect
The link_to helper creates an anchor tag with href set to the URL generated by user_path(42). The class attribute is added as specified.
📝 Syntax
intermediate2:00remaining
Which option correctly uses link_to with a block?
Which of the following is the correct syntax to use link_to with a block in Rails?
Attempts:
2 left
💡 Hint
Blocks in Ruby can be written with do...end or curly braces, but link_to with block usually uses do...end with proper indentation.
✗ Incorrect
Option A correctly uses do...end block syntax with link_to, passing the URL as the first argument and the block returning the link text.
🔧 Debug
advanced2:00remaining
Why does this link_to raise an error?
Given this code:
Why does it raise an error?
link_to 'Edit', edit_user_path
Why does it raise an error?
Ruby on Rails
link_to 'Edit', edit_user_pathAttempts:
2 left
💡 Hint
Check the method signature of edit_user_path in Rails routes.
✗ Incorrect
The edit_user_path helper expects a user id argument to generate the correct URL. Omitting it causes an ArgumentError.
❓ state_output
advanced2:00remaining
What is the value of the generated URL?
Given this route:
and this code:
What is the full URL generated?
resources :articles
and this code:
article_url(10, host: 'example.com')
What is the full URL generated?
Ruby on Rails
article_url(10, host: 'example.com')
Attempts:
2 left
💡 Hint
article_url generates a full URL including protocol and host.
✗ Incorrect
article_url generates a full URL with http by default and the given host 'example.com'.
🧠 Conceptual
expert3:00remaining
Which option correctly explains polymorphic_url usage?
In Rails, what does polymorphic_url(@comment) do if @comment belongs to a Post?
Attempts:
2 left
💡 Hint
Polymorphic helpers build URLs based on the object and its associations.
✗ Incorrect
polymorphic_url(@comment) generates the URL for the comment resource based on its class, like /comments/1. It ignores the parent post unless you pass an array like polymorphic_url([@comment.post, @comment]).