Welcome to the Treehouse Community
Looking to learn something new?
Yiheng Chu8,465 Points
Why I can't use redirect_to '/pages/:id'? It said the 'id' params doesn't passed into the #show action.
All info is above. Thank you!
Jay McGavrenTreehouse Teacher
redirect_to("/pages/:id") will literally redirect the browser to load the path
"/pages/:id". So if you have a
get "/pages/:id", to: "pages#show" route set up, then when
show is called,
params[:id] will be set to the string
":id", which is not what you want.
Instead, you should pass
redirect_to a model object that has its
id attribute set:
Or you should interpolate the ID into a string, and pass that to
Here's what it would look like in a controller action:
def create @page = Page.new(page_params) if @page.save redirect_to @page, notice: 'Page was successfully created.' else render :new end end