@name
represents an array of single object of Quest model. To get the id of that object, use
<p><%= @name.first.id %></p>
or change your controller code to
@name = Quest.where(category: 'cat1').sample
and then do
<p><%= @name.id %></p>
solved What is #<..> on Ruby on Rails?