Recall & Review
beginner
What does the
link_to helper do in Rails?The
link_to helper creates an HTML anchor (<a>) tag that links to a specified URL or path. It helps generate clickable links easily in views.Click to reveal answer
beginner
How do you generate a URL for a named route in Rails?
You use URL helpers that Rails creates from your routes, like
posts_path or post_url(@post). These helpers return the path or full URL for the route.Click to reveal answer
intermediate
What is the difference between
_path and _url helpers in Rails?_path helpers return a relative path (like /posts/1), while _url helpers return the full URL including the domain (like http://example.com/posts/1).Click to reveal answer
intermediate
How can you add HTML options like CSS classes or data attributes to a
link_to helper?You pass a hash of HTML options as the last argument to <code>link_to</code>. For example, <code>link_to 'Home', root_path, class: 'nav-link', data: { toggle: 'dropdown' }</code> adds a class and data attribute.Click to reveal answer
intermediate
What helper would you use to create a link that submits a DELETE request in Rails?
Use
link_to with the method: :delete option. Rails uses JavaScript to convert the link click into a DELETE HTTP request.Click to reveal answer
Which helper generates a clickable link in Rails?
✗ Incorrect
link_to creates clickable links. url_for generates URLs but not links.What does
posts_path return?✗ Incorrect
posts_path returns the relative path for posts.How do you add a CSS class to a
link_to helper?✗ Incorrect
You add HTML options like class using a hash as the last argument.
Which option makes
link_to send a DELETE request?✗ Incorrect
method: :delete tells Rails to send a DELETE HTTP request.What is the difference between
post_path(@post) and post_url(@post)?✗ Incorrect
post_path returns relative path; post_url returns full URL with domain.Explain how to create a link in Rails that looks like a button and sends a DELETE request when clicked.
Think about link_to options and styling.
You got /4 concepts.
Describe the difference between URL helpers ending with _path and those ending with _url in Rails.
Consider what the browser needs to navigate.
You got /4 concepts.