# Newbie: undefined method

**URL:** <https://www.ruby-forum.com/t/newbie-undefined-method/78543>\
**Category:** Ruby\
**Created:** [March 8, 2006, 5:24pm UTC](https://www.ruby-forum.com/t/newbie-undefined-method/78543 "2006-03-08T17:24:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 8, 2006, 5:24pm UTC](https://www.ruby-forum.com/t/newbie-undefined-method/78543/1 "2006-03-08T17:24:12Z")

</div>

I get “undefined method `name’ for #TSPProcess:0x38c7fc0” when I  
access the page with the template:

\<% @processes.each do |asd| %\>

 \<%= render(:inline =\> "#{process.name}")%\> \<% end %\>

The TSPProcess.rb is:

class TSPProcess  
@name = “Nothing”  
attr\_reader :name  
attr\_writer :name  
end

I tried defining name and name= and I get the same error.  
The controller:

require ‘TSPProcess’  
class ProcessesController \< ApplicationController  
def index  
@processes = Array.new  
a = TSPProcess.new  
@processes \<\< a  
end  
end

Any help for a beginner?

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 8, 2006, 5:30pm UTC](https://www.ruby-forum.com/t/newbie-undefined-method/78543/2 "2006-03-08T17:30:20Z")

</div>

The template should read:  
\<% @processes.each do |process| %\>

 \<%= render(:inline =\> "#{process.name}")%\> \<% end %\>

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 8, 2006, 5:42pm UTC](https://www.ruby-forum.com/t/newbie-undefined-method/78543/3 "2006-03-08T17:42:40Z")

</div>

On Mar 8, 2006, at 5:23 PM, removed\_email\_address@domain.invalid wrote:

> class TSPProcess  
> @name = “Nothing”  
> attr\_reader :name  
> attr\_writer :name  
> end

The @name could be causing some problems. If you really want a  
default of “Nothing”, you should move it to the #initialize method.

def initialize  
@name = “Nothing”  
end

Try:

class TSPProcess  
attr\_accessor :name  
end

and in your template:

\<% @processes.each do |process| %\>

 \<%= render(:inline =\> "#{process.name or "Nothing"}")%\> \<% end %\>

> require ‘TSPProcess’

You should ruby’s convention for file-naming: require ‘tsp\_process’

> class ProcessesController \< ApplicationController  
> def index  
> @processes = Array.new  
> a = TSPProcess.new  
> @processes \<\< a  
> end  
> end

You could shorten this to:  
class ProcessesController \< ApplicationController  
def index  
@processes = [TSPProcess.new]  
end  
end

– Daniel

---

<div class="post-metadata">

**Author:** ![casper\_the\_ghost](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/c/58956e/32.png) [@casper\_the\_ghost](https://www.ruby-forum.com/u/casper_the_ghost)\
**Post date:** [March 8, 2006, 6:01pm UTC](https://www.ruby-forum.com/t/newbie-undefined-method/78543/4 "2006-03-08T18:01:06Z")

</div>

This worked out for me, thank you.
