Problem with IronRubyMvc and IR 0.9.1

Hi,
tried to get running casualjim/ironrubymvc master from github to work.
(I’m about to write a IronRuby MVC plugin for OpenSource CMS Umbraco
with this, see: http://www.umbraco.org)

Problem is calling a controller more than once.

With IR 0.9.0 it worked quite well. But now when I recall the same
controller url (eg. /Home) I get error “unknown member: HomeController”.

Searching the code I found:

  1. Error comes from RubyEngine.GetGlobalVariable() for “HomeController”

  2. Cause for this seams to be the before executed method call to
    RubyEngine.RemoveClassFromGlobals()

I tried to comment out call to 2. This works better, but the
HomeController now adds all Filter methods again and again, everytime I
call the controller.
So I tried around some hours to find out what’s going on and for a
better way to remove the HomeController from the IronRuby engine global
scope but without any success.

Any ideas to fix this? Immo

I use an ironruby built on 28/09/2009 that is the one in the github repo
if
you build ironruby mvc. I can see the Home bpage of the test site.

Did you build ironruby mvc from source recently?


Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

Ivan, I’m going to finally pull all your changes and I can update
IronRuby in the process. Would it be helpful to just add IronRuby as a
submodule so you can just depend on the csproj files rather than raw
assemblies? Then it could be added to your build servers and at least
have some CI – as long as your tests are suitable :slight_smile: Worst comes to
worse a watir script testing that the demo website still works would be
appropriate.

~js


From: [email protected]
[[email protected]] on behalf of Ivan Porto C.
[[email protected]]
Sent: Sunday, October 11, 2009 11:39 AM
To: [email protected]
Subject: Re: [Ironruby-core] Problem with IronRubyMvc and IR 0.9.1

I use an ironruby built on 28/09/2009
that is the one in the github repo if you build ironruby mvc. I can see
the Home bpage of the test site.

Did you build ironruby mvc from source recently?


Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

On Sun, Oct 11, 2009 at 8:19 PM, Immo Wache
<[email protected]mailto:[email protected]> wrote:
Hi,
tried to get running casualjim/ironrubymvc master from github to work.
(I’m about to write a IronRuby MVC plugin for OpenSource CMS Umbraco
with this, see: http://www.umbraco.org)

Problem is calling a controller more than once.

With IR 0.9.0 it worked quite well. But now when I recall the same
controller url (eg. /Home) I get error “unknown member: HomeController”.

Searching the code I found:

  1. Error comes from RubyEngine.GetGlobalVariable() for “HomeController”

  2. Cause for this seams to be the before executed method call to
    RubyEngine.RemoveClassFromGlobals()

I tried to comment out call to 2. This works better, but the
HomeController now adds all Filter methods again and again, everytime I
call the controller.
So I tried around some hours to find out what’s going on and for a
better way to remove the HomeController from the IronRuby engine global
scope but without any success.

Any ideas to fix this? Immo

Posted via http://www.ruby-forum.com/.

oic… yes that is my fault
I have to change the way I deal with requiring files and clearing out
old
classes.

I’ll go for a load strategy instead of removing them from the Globals
collection, but won’t be today though.

Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

Hi casualjim,

thanks alot for your reply. Yes it is the plain source from your master
fork, with the ironruby assemblies from its dependencies folder (IR
0.9.1 ones).

Calling once the Home page works fine. But when I recall it later again
it fails. Reason why is the matter about the global vars I described. I
use VS 2008 Pro SP1 de-edition.

When you can see the Home page, simply try refresh the page again. This
should produce the error.

Immo

Ivan Porto carrero wrote:

I use an ironruby built on 28/09/2009 that is the one in the github repo
if
you build ironruby mvc. I can see the Home bpage of the test site.

Did you build ironruby mvc from source recently?


Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

Hi Ivan,

be imressed about your prompt reply. Good to read you can reproduce the
issue.
To be honest, I fiddeled around with the code some nights now, so I
don’t expect a solution from today to now. Meanwhile I learned (Almost
Everything I never ever wanted to know) about Ruby, and it seams now to
me that Ruby really dislike the idea to remove something which is global
defined before.

Meanwhile I’m listen to silly http://www.youtube.com/watch?v=tE17zPKfhYs
to keep up my mood and try to get the old deactivated project
IronRubyMvcLibrary.Tests from your master running.

Wish you all best success for a solution,
Immo

Ivan Porto carrero wrote:

oic… yes that is my fault
I have to change the way I deal with requiring files and clearing out
old
classes.

I’ll go for a load strategy instead of removing them from the Globals
collection, but won’t be today though.

Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.

I’ve updated the ironruby libraries to what’s in github currently.

I pulled in your changes Immo but when i compiled the app I couldn’t
serve
any pages up it complained about not being able to find the correct
IronRuby
yada yada.

Anyway the fix I had in mind was removing 1 line of code and reloading
works
again. The thing is that now if you update a controller file you need to
restart the web application.

Does windows have an equivalent of touch ? because doing that could be
as
easy as touch web.config
otherwise I use the following cheat I add a space in web.config so it
hashes
differently and save the web.config file.

Thanks for fixing the tests :slight_smile: I’ll see if I can cherry-pick your
changes
later.

The extension method RequireFile for ruby does that respect when I would
redefine the require statement to keep track of classes contained in a
file
and reload them on each request when compiled in debug mode?


Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

Hi Ivan,
many thanks again to care about this problem.

Ivan Porto carrero wrote:

I pulled in your changes Immo but … complained about not being able
to find the correct IronRuby yada yada.

Oh, my fault, sorry. I merged my local copy to my (first!) github fork
(the one from you) slightly to much careful. There was a local copy
reference of this assembly missing. Its fixed and pushed now.

Anyway the fix I had in mind was removing 1 line of code and reloading
works again. The thing is that now if you update a controller file you
need to restart the web application.

Hmm, your solution seams to me for a cure of symthomes only. Ok it
passes my tests but the problem with this solution is the one I
described earlier:

“I tried to comment out call to 2. This works better, but the
HomeController now adds all Filter methods again and again, everytime I
call the controller.”

To make this proveable I just added and pushed another test for this:

[when_a_ruby_controller_was_resolved_twice->action_filters_count_should_be_
equal]

This issue effects to the demo/test project “IronRubyMvcWeb” that you
get
on the browser at first call of /Home controller:

==============================
Hello world
From method filter

ASP.NET MVC w/ IronRuby Demo
… rabarber, rabarber…

and on the second call:

==============================
Hello world
From method filter
Hello world <== these are the readded filters
From method filter

ASP.NET MVC w/ IronRuby Demo
… rabarber, rabarber…

So I need to touch web.config on every subsequent call to an
(unmodified) IronRuby controller :-(((

Immo

Hi Tomas,
thanks alot for joining the discussion. Your idea sounds interesting.
I’ll try it out now.

Immo

Tomas M. wrote:

“The extension method RequireFile for ruby does that respect when I
would redefine the require statement to keep track of classes contained
in a file and reload them on each request when compiled in debug mode?”

No, there is no dynamic invocation of “require” method going on. If you
need to call “require” you can use Engine.Operations.InvokeMember(nil,
“require”, fileName);

Tomas

“The extension method RequireFile for ruby does that respect when I
would redefine the require statement to keep track of classes contained
in a file and reload them on each request when compiled in debug mode?”

No, there is no dynamic invocation of “require” method going on. If you
need to call “require” you can use Engine.Operations.InvokeMember(nil,
“require”, fileName);

Tomas

From: [email protected]
[mailto:[email protected]] On Behalf Of Ivan Porto
Carrero
Sent: Tuesday, October 13, 2009 4:37 AM
To: [email protected]
Subject: Re: [Ironruby-core] Problem with IronRubyMvc and IR 0.9.1

I’ve updated the ironruby libraries to what’s in github currently.

I pulled in your changes Immo but when i compiled the app I couldn’t
serve any pages up it complained about not being able to find the
correct IronRuby yada yada.

Anyway the fix I had in mind was removing 1 line of code and reloading
works again. The thing is that now if you update a controller file you
need to restart the web application.

Does windows have an equivalent of touch ? because doing that could be
as easy as touch web.config
otherwise I use the following cheat I add a space in web.config so it
hashes differently and save the web.config file.

Thanks for fixing the tests :slight_smile: I’ll see if I can cherry-pick your
changes later.

The extension method RequireFile for ruby does that respect when I would
redefine the require statement to keep track of classes contained in a
file and reload them on each request when compiled in debug mode?


Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

On Mon, Oct 12, 2009 at 2:09 AM, Immo Wache
<[email protected]mailto:[email protected]> wrote:
Hi Ivan,

be imressed about your prompt reply. Good to read you can reproduce the
issue.
To be honest, I fiddeled around with the code some nights now, so I
don’t expect a solution from today to now. Meanwhile I learned (Almost
Everything I never ever wanted to know) about Ruby, and it seams now to
me that Ruby really dislike the idea to remove something which is global
defined before.

Meanwhile I’m listen to silly http://www.youtube.com/watch?v=tE17zPKfhYs
to keep up my mood and try to get the old deactivated project
IronRubyMvcLibrary.Tests from your master running.

Wish you all best success for a solution,
Immo

Ivan Porto carrero wrote:

oic… yes that is my fault
I have to change the way I deal with requiring files and clearing out
old
classes.

I’ll go for a load strategy instead of removing them from the Globals
collection, but won’t be today though.

Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.

Posted via http://www.ruby-forum.com/.


Ironruby-core mailing list
[email protected]mailto:[email protected]
http://rubyforge.org/mailman/listinfo/ironruby-core

Hi Tomas,

No success so far, all variants produce the same exception:
“InvalidOperationException: Empty scope has no global scope.” ???

I tried following variants:

Engine.Operations.InvokeMember(null, “require”,
PathProvider.MapPath(path));
Engine.Operations.InvokeMember(Context, “require”,
PathProvider.MapPath(path));
Engine.Operations.InvokeMember(Context.TopGlobalScope, “require”,
PathProvider.MapPath(path))
Engine.Operations.InvokeMember(Engine, “require”,
PathProvider.MapPath(path))
Engine.Operations.InvokeMember(Engine.Runtime.Globals, “require”,
PathProvider.MapPath(path))
Engine.Operations.InvokeMember(Engine.GetScope(null), “require”,
PathProvider.MapPath(path))

with:

Engine = Ruby.GetEngine(Runtime);
Context = Ruby.GetExecutionContext(Engine);
CurrentScope = Engine.CreateScope();
Operations = Engine.CreateOperations();

Any ideas what’s wrong?

Hope for some help, Immo

Tomas M. wrote:

“The extension method RequireFile for ruby does that respect when I
would redefine the require statement to keep track of classes contained
in a file and reload them on each request when compiled in debug mode?”

No, there is no dynamic invocation of “require” method going on. If you
need to call “require” you can use Engine.Operations.InvokeMember(nil,
“require”, fileName);

Hi Immo,
I’ve been able to merge your changes, will push them later.

I’ll see what I can do about reloading, but can’t promise anything as I
don’t have a lot of time to spend on this.

Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
GSM: +32.486.787.582
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

Hi Ivan,

I see you have alot to do with your book and things. Neverless thank you
for your help. May be I can support you in my issue with help of others
from this forum.

Meanwhile I managed to get the tip from Tomas working by execute a plain
Ruby script (I know its not a professional solution):

string scriptPath = “require '” + PathProvider.MapPath(path) + “’”;
Engine.ExecuteScript(scriptPath, CurrentScope));

This works much betten than before:

  1. When the controller is called first time,
    the HomeController.rb script is executed.

  2. When the controller is called again, the script
    will not executed again. This resolves perfect
    the “Filter adding” problem.

  3. When I modify the HomeController.rb script,
    the script will not be executed again. To get it
    executed, I need to touch web.config/Restart ASP.NET.

Issue No. 3 is not perfect to me, because I’m about to write an IronRuby
MVC extention module for Umbraco CMS. The CMS backend developer should
be able to modify ruby scripts via web interface, and restart ASP.NET
takes a lot of time because the CMS has a bunch of assemblies to reload
which takes almost 30 sec. on my dev IIS.

Neverless I will put the modification to my branch, with this I’m be
able to carry on with my own extention module.

BTW It would be real great, if anyone has a tip to my
“Engine.Operations.InvokeMember(” problem above.

Greetings, Immo

Ivan Porto carrero wrote:

Hi Immo,
I’ve been able to merge your changes, will push them later.

I’ll see what I can do about reloading, but can’t promise anything as I
don’t have a lot of time to spend on this.

Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.

I can check that in becuase that require is working for me now. I didn’t
use
the way Tomas suggested because that didn’t work for me either. It
complained about the scope not being the global scope or the global
scope
being empty.
I just execute a script. This fixes your issue but will require you to
restart the application to pick up any changes at this moment.

Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

Hi Ivan,

good news. If you got it ready, yes please check in. So I can update my
branch and test it.

Immo

Ivan Porto carrero wrote:

I can check that in becuase that require is working for me now.

Seems like a bug. I’ll take a look.

Tomas

Hi Ivan,
thanks for sharing your solution. I slightly extended it with
PathProvider.MapPath. Also I fixed a bug with my added xunit tests.
http://github.com/iwache/ironrubymvc/commit/b6c6e425343925b9f7a464ee43c3f80cf93c8cec

Immo

done
these are the changes I made, almost none :slight_smile:
http://github.com/casualjim/ironrubymvc/commit/bc80a3057f48c3064ddb99f5700d8279f0455189

Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

Engine.Operations.InvokeMember(null, “require”, “xxx”);

Raises an exception with the latest bits:
System.MissingMethodException: private method `require’ called for
nil:NilClass

Which is expected. I forgot the Kernel methods are all private.

Tomas

How do you want to provide different development environments for
ironrubymvc ?
I can either do it by creating the configuration section I’ve been
planning,
this would be used to provide load paths for example for libraries
outside
of the web project.

I can have a parameter there something like MvcEnv which will set the
ruby
constant MVC_ENV

based on the value of that constant it would then be possible to provide
different behavior for the require statement, much like rails does.

Would it be a good idea to enforce a single class per file for
controllers
and helpers, or would it be better to leave that up to the judgment of
the
user of the framework?

Should there be validation for naming conventions. like a file
home_controller.rb has to define the HomeController class?


Met vriendelijke groeten - Best regards - Salutations
Ivan Porto C.
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs