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?
The template should read:
<% @processes.each do |process| %>
<%= render(:inline => "#{process.name}")%> |
<% end %>
On Mar 8, 2006, at 5:23 PM, [email protected] 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
This worked out for me, thank you.