And then, taking into account that ruby is a fully interpreted language,
how come my changes are being ignored???
Saludos
Sas
PS: I apologize if this is a stupid question. I'm just taking my very
first steps with ruby and with rails.
if you are running in fastcgi mode you script, and it's dependancies,
are
loaded only once. is this the case?
-a
I followed the install method from Agile Web Development with Rails,
that is I'm using WEBrick, and started it with ruby script/server (well,
in fact I'm using radrails, but I guess it's the same), so I guess I'm
not using fastcgi.
- you are not using that session.rb, another one exists on your system
- you are putting you edit in the wrong place in that file, show us the
actual code, not a snippet
- you are not restarting your server or otherwise loading the code
you can easily test this from the command line, which will be a whole lot
easier than doing from within rails. for example
ruby -r cgi -r cgi/session -e' s = CGI::Session.new(CGI.new); p s.sayHello ' < /dev/null
when this works you will have made the edit in the right place.
btw. it's a horrible idea to change the core lib files in that way. ruby's
open classes provides a method about 1000 times easier and safer than that to
make changes to core classes:
jib:~ > cat a.rb
class CGI
class Session
def say_hello
puts 'hi'
end
end
end
jib:~ > ruby -r cgi -r cgi/session -r ./a.rb -e' s = CGI::Session.new(CGI.new); s.say_hello ' < /dev/null
hi
in otherwords you do not need to, nor should you, edit session.rb to make this
change.
hth.
-a
···
On Fri, 7 Apr 2006, sas sas wrote:
thanks for the advice, but I'm stuck with something even more trivial
I tried adding the following in C:\ruby\lib\ruby\1.8\cgi\session.rb
def sayHello
"hello"
end
and then in a view
<%= session.sayHello %>
but then I get the following error
Showing app/views/resolucion/list.rhtml where line #19 raised:
undefined method `sayHello' for #<CGI::Session:0x38f6bd0>
Seems like my changes are completely ignored...
any idea???
--
be kind whenever possible... it is always possible.
- h.h. the 14th dali lama
and then, I saw the error saying something about
CGI::Session
In the C:\ruby\lib\ruby\1.8\cgi\session.rb file, the Session declaration
wa inside the CGI class, so I had to
class CGI::Session
def sayHello
"hello"
end
end
and it just worked
so I went on and defined
class CGI::Session
def data
unless @data @data = @dbman.restore
end @data
end
def each(&block)
data.each &block
end
def each_pair(&block)
data.each_pair &block
end
end
BTW, is there some way to redirect a bunch of methods (each, each_key,
each_pair, each_value, empty?, to_a, etc... I guess you know what I
mean) from self to self.data?
and then, to give it a try, in a view I added the following
<table border="1">
<tr><th colspan="2">params</th></tr>
<tr><th>key</th><th>value</th></tr>
<% session.each_pair { |key, value| %>
<tr><th><%= h key %></th><th><%= h value %></th></tr>
<% } %>
</table>
Well, that's all
Saludos
Sas
PS: I'm pretty impressed with how easy is to extend ruby. Just imagine
doing such a thing in asp...
BTW, is there some way to redirect a bunch of methods (each, each_key,
each_pair, each_value, empty?, to_a, etc... I guess you know what I
mean) from self to self.data?
BTW, is there some way to redirect a bunch of methods (each, each_key,
each_pair, each_value, empty?, to_a, etc... I guess you know what I
mean) from self to self.data?