print id for object in controller

13 views
Skip to first unread message

Anujeet Kaur

unread,
Dec 9, 2015, 6:29:56 AM12/9/15
to Ruby on Rails: Talk
Hello everyone, I am new to ruby, i'm facing issues in it.
When i try to print id for object in loop, i get an error

Here is my code

def index
@lists = List.all
@lists.each do |list|
raise list.id
end
exit
end

I'm getting the error
"

exception class/object expected

"

Colin Law

unread,
Dec 9, 2015, 6:49:32 AM12/9/15
to Ruby on Rails: Talk
On 9 December 2015 at 11:05, Anujeet Kaur <anu...@smartshore.nl> wrote:
> Hello everyone, I am new to ruby, i'm facing issues in it.
> When i try to print id for object in loop, i get an error
>
> Here is my code
>
> def index
> @lists = List.all
> @lists.each do |list|
> raise list.id

The raise method raises an exception (but you are not calling it
correctly). to print the id you want
puts list.id

As a newcommer I suggest you work right through a good tutorial (such
as railstutorial.org, which is free to use online), that will show you
the basics of Ruby and Rails.

Colin
Reply all
Reply to author
Forward
0 new messages