Newbie: undefined method

T

tim.hennekey

I get "undefined method `name' for #<TSPProcess:0x38c7fc0>" when I
access the page with the template:

<% @processes.each do |asd| %>
<tr>
<td><%= render:)inline => "#{process.name}")%></td>
</tr>
<% 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?
 
T

tim.hennekey

The template should read:
<% @processes.each do |process| %>
<tr>
<td><%= render:)inline => "#{process.name}")%></td>
</tr>
<% end %>
 
D

Daniel Harple

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| %>
<tr>
<td><%= render:)inline => "#{process.name or "Nothing"}")%></td>
</tr>
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,777
Messages
2,569,604
Members
45,227
Latest member
Daniella65

Latest Threads

Top