rails

Pass Information from URL in Rails

Shou Arisaka
1 min read
Nov 13, 2025
// routes.rb
get 'userinfo/show/:id' => 'userinfo#show',as:'userinfo_show'
// show.html.erb
<%= Userinfo.find(params[:id]).name %>

First, use rails c to put data into the model in advance. In this example, I'm using id:4 because data with id:4 happened to remain.

In this state, when you access userinfo/show/4, when you apply the :hoge part specified in routes.rb to the URL, that character (number) is sent to Rails as is.

As for how it's sent, it's sent to an array called params.

In this example, which is also mentioned on various other sites, it's like outputting specific data from the model based on the id number in the URL.

Share this article

Shou Arisaka Nov 13, 2025

๐Ÿ”— Copy Links