Challenge 2: Reading From params — Solution class CommentsController < ApplicationController def index post_id = params[:post_id] # from the route -- /posts/:post_id/comments sort_order = params[:sort] # from the query string -- ?sort=newest @post = Post.find(post_id) @comments = sort_order == "newest" ? @post.comments.order(created_at: :desc) : @post.comments end end =begin Notes: - params[:post_id] comes from the nested route pattern /posts/:post_id/comments (Chapter 2's nested resources) -- Rails names the parameter post_id specifically because the route is nested under posts, distinguishing it from a plain :id. - params[:sort] comes from the query string (?sort=newest) in the actual request URL, but it's read through the exact same params hash as post_id -- no separate req.query access required, unlike Express. - The ternary checks sort_order and conditionally orders the post's comments -- this demonstrates params values arriving as plain strings ("newest"), which is true regardless of whether the original value came from a route segment, a query parameter, or (as Challenge 3 shows) a form body. =end