Kang-Kyu Lee

October 31, 2024

Ruby shorts

In Ruby coding, there's this "@" and it does passing something (a variable to another method). Let me show you what I mean.

Here's an example in Ruby on Rails. When you have that "@" in the code, it shows the number on the screen, as you see.

def show
  @post = Post.find(params[:id])
end

<%= @post %>

If I remove it from the same code, it does not any more.

def show
  post = Post.find(params[:id])
end

<%= post %>

See you next time!