Forum: IronRuby Question about Ivan Porto carrero MVC Sample

Posted by Mohammad Azam (azamsharp)
on 2009-06-23 17:49
Hi Ivan Porto carrero,

Great work on the MVC IronRuby sample!

I am curious to know how it works! I created an ASP.NET MVC application.
I created the controller and view but how will the views get called.

Here is my controller:

require 'application_controller'

class HomeController < ApplicationController


  def index
    @message = "Welcome from IronRuby!"
    view('Index')
  end

  def about
    view('Index')
  end

end


And here is the view:

<h2><%= html.encode(view_data.message) %></h2>
    <p>
        To learn more about ASP.NET MVC visit <a
href="http://asp.net/mvc" title="ASP.NET MVC
Website">http://asp.net/mvc</a>.
</p>


Thanks!
Posted by Mohammad Azam (azamsharp)
on 2009-06-23 17:58
For some reason it is not running for me out of the box. When I run the 
application the following exception is thrown:

Could not load file or assembly 'System.Data.SQLite' or one of its 
dependencies. An attempt was made to load a program with an incorrect 
format.

Even though the reference to System.Data.SQLite is already made!
Posted by Ivan Porto carrero (casualjim)
on 2009-06-23 18:39
(Received via mailing list)
You have a 32-bit machine right?
You need to download the 32-bit version of the System.Data.SQLite.dll 
and
replace that one.. I've got one here if you want it, email me off-list
---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
Posted by Ivan Porto carrero (casualjim)
on 2009-06-23 18:53
(Received via mailing list)
Asp.net MVC has the ability to add view engines
Each view engine defines a bunch of search patterns, and you can 
configure
the location of the views but the convention is views so I'd stick with 
that
:)
When you request the view "index" the controller will ask the view 
engines
collection if it can find a view with that name in a location
/views/controllername/
The first view that matches the file name like index.html.erb or 
index.aspx
also selects the view engine. From there on the view engine reads the 
file
and executes it, after setting a bunch of variables that can be used in 
the
view script like the view data dictionary.


---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
Posted by Mohammad Azam (azamsharp)
on 2009-06-23 20:31
Is there any special place where you register the ViewEngine. I have 
files with extensions .rhtml but they are not being picked up by the MVC 
application.
Posted by Ivan Porto carrero (casualjim)
on 2009-06-23 20:36
(Received via mailing list)
rename them to .html.erb that should work.

---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
Posted by Mohammad Azam (azamsharp)
on 2009-06-23 20:39
I tried it!

It is throwing a 404 error:

 The resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its 
dependencies) could have been removed, had its name changed, or is 
temporarily unavailable.  Please review the following URL and make sure 
that it is spelled correctly.

Requested URL: /account


Here is the controller:



class AccountController < Controller

  def index
    @message = "Welcome from IronRuby!"
    return view
  end

  def about
    return view
  end

end

And here is the View:

<div>

<h2> Hello from IronRuby! </h2>
</div>

Thanks,
Posted by Mohammad Azam (azamsharp)
on 2009-06-23 20:58
Do I also need mvc_application even thought I am not using the 
LightSpeed data access layer?
Posted by Mohammad Azam (azamsharp)
on 2009-06-23 20:59
If I load the Default.aspx page I get the following error:

 The incoming request does not match any route.
Description: An unhandled exception occurred during the execution of the 
current web request. Please review the stack trace for more information 
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The incoming request does 
not match any route.

Source Error:

Line 16: 
HttpContext.Current.RewritePath(Request.ApplicationPath, false);
Line 17:             IHttpHandler httpHandler = new MvcHttpHandler();
Line 18:             httpHandler.ProcessRequest(HttpContext.Current);
Line 19:             HttpContext.Current.RewritePath(originalPath, 
false);
Line 20:         }


Source File: 
C:\Projects\IronRubyMVCWebApps\IronRubyMVCWebApps\IronRubyMVCWebApps\Default.aspx.cs 
Line: 18


I have all the routes in the Routes.rb file:

require 'mvc_application'


#default routes
$routes.ignore_route("{resource}.axd/{*pathInfo}");

$routes.map_route("default", "{controller}/{action}/{id}", {:controller 
=> 'Home', :action => 'index', :id => ''})


Posted by Ivan Porto carrero (casualjim)
on 2009-06-23 21:17
(Received via mailing list)
Does the sample work on your machine if you use the correct sqlite 
assembly?

---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
Posted by Mohammad Azam (azamsharp)
on 2009-06-23 21:18
I have not tried it with the SqlLite assembly.

I am simply trying to say "/home" and it should trigger the 
HomeController.

I am following this example:

http://haacked.com/archive/2008/04/22/defining-asp.net-mvc-routes-and-views-in-ironruby.aspx
Posted by Mohammad Azam (azamsharp)
on 2009-06-23 21:21
Is there any link between the IronRubyMvcLibrary?

Do I need that library?

How will the application know to load the routes from routes.rb file?
Posted by Mohammad Azam (azamsharp)
on 2009-06-23 21:23
Here is the latest error:

 The incoming request does not match any route.
Description: An unhandled exception occurred during the execution of the 
current web request. Please review the stack trace for more information 
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The incoming request does 
not match any route.

Source Error:

Line 16: 
HttpContext.Current.RewritePath(Request.ApplicationPath, false);
Line 17:             IHttpHandler httpHandler = new MvcHttpHandler();
Line 18:             httpHandler.ProcessRequest(HttpContext.Current);
Line 19:             HttpContext.Current.RewritePath(originalPath, 
false);
Line 20:         }


Source File: 
C:\Projects\IronRubyMVCWebApps\IronRubyMVCWebApps\IronRubyMVCWebApps\Default.aspx.cs 
Line: 18
Posted by Mohammad Azam (azamsharp)
on 2009-06-23 21:31
Where can I download the 32 bit version?

Ivan Porto carrero wrote:
> You have a 32-bit machine right?
> You need to download the 32-bit version of the System.Data.SQLite.dll 
> and
> replace that one.. I've got one here if you want it, email me off-list
> ---
> Met vriendelijke groeten - Best regards - Salutations
> Ivan Porto Carrero
> Blog: http://flanders.co.nz
> Twitter: http://twitter.com/casualjim
> Author of IronRuby in Action (http://manning.com/carrero)
Posted by Ivan Porto carrero (casualjim)
on 2009-06-23 21:38
(Received via mailing list)
Sqlite lib:
http://sourceforge.net/project/showfiles.php?group_id=132486&package_id=145568

You need to have a reference to the ironrubymvc library and compile the
asp.net mvc project once from then on things should start to work.


Getting started

   1. Install ASP.NET MVC (link?)
   2. Create a new ASP.NET MVC project in Visual Studio
   3. Add a reference to System.Web.Mvc.IronRuby.dll
   4.

   Open Global.asax.cs and ...

   // add this to your usings using System.Web.Mvc;

   // make the subclass of "MvcApplication" be "RubyMvcApplication"
   namespace MyIronRubyMvcApp {

   public class MvcApplication : RubyMvcApplication {

   }

   }
   5.

   Create Routes.rb and define a default route:

   $routes.ignore_route "{resource}.axd/{*pathInfo}" $routes.map_route
   "default", "{controller}/{action}/{id}", :controller => 'Home', 
:action =>
   'index', :id => ''

---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
GSM: +32.486.787.582
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
Posted by Ivan Porto carrero (casualjim)
on 2009-06-23 21:43
(Received via mailing list)
The ironruby mvc library being System.Web.Mvc.IronRuby.dll
and the routes got borked
$routes.ignore_route "{resource}.axd/{*pathInfo}"
$routes.map_route "default", "{controller}/{action}/{id}", :controller 
=>
'Home', :action => 'index', :id => ''"

I suggest
you take jimmy's repository of ironrubymvc. I will sometimes break
existing functionality
http://github.com/jschementi/ironrubymvc/tree/master

You should also be able to re-use existing filters defined in C# etc.


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



On Tue, Jun 23, 2009 at 9:33 PM, Ivan Porto Carrero 
<ivan@flanders.co.nz>wrote:

>    1. Install ASP.NET MVC (link?)
>
>
> $routes.map_route "default", "{controller}/{action}/{id}", :controller =>
'Home', :action => 'index', :id => ''"
Posted by Mohammad Azam (azamsharp)
on 2009-06-23 21:46
In your download you never subclass from RubyMvcApplication. I have 
tried to subclass from RubyMvcApplication but it is giving me the same 
issue:

 The incoming request does not match any route.
Description: An unhandled exception occurred during the execution of the 
current web request. Please review the stack trace for more information 
about the error and where it originated in the code.

Exception Details: System.Web.HttpException: The incoming request does 
not match any route.

Source Error:

Line 16: 
HttpContext.Current.RewritePath(Request.ApplicationPath, false);
Line 17:             IHttpHandler httpHandler = new MvcHttpHandler();
Line 18:             httpHandler.ProcessRequest(HttpContext.Current);
Line 19:             HttpContext.Current.RewritePath(originalPath, 
false);
Line 20:         }


Source File: 
C:\Projects\IronRubyMVCWebApps\IronRubyMVCWebApps\IronRubyMVCWebApps\Default.aspx.cs 
Line: 18
Posted by Mohammad Azam (azamsharp)
on 2009-06-23 22:01
I copied your code to a new project and still it is giving me issues. It 
is not picking up the Routes.rb file.

Is there anything interesting in ApplicationController since I am not 
using ApplicationController.
Posted by Ivan Porto carrero (casualjim)
on 2009-06-23 22:02
(Received via mailing list)
http://github.com/casualjim/ironrubymvc-sample/blob/75a1aee810e2b2b5a99a538cc73ca89b0a3df438/IR_Todo/Global.asax.cs#L12

You also need to change this assembly redirection in the config file to
point to the correct version number of your sqlite assembly.
http://github.com/casualjim/ironrubymvc-sample/blob/75a1aee810e2b2b5a99a538cc73ca89b0a3df438/IR_Todo/Web.config#L143

---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
Posted by Ivan Porto carrero (casualjim)
on 2009-06-23 22:02
(Received via mailing list)
which OS and web server are you using?
---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
Posted by Mohammad Azam (azamsharp)
on 2009-06-23 22:06
I am not using SqlLite anymore!!

I just want to trigger the action and display the view.

I am running ASP.NET 3.5 using ASP.NET build in server.

Here is everything:

Routes.rb:

#default routes
$routes.ignore_route("{resource}.axd/{*pathInfo}");

$routes.map_route("default", "{controller}/{action}/{id}", {:controller 
=> 'Home', :action => 'index', :id => ''})


home_controller.rb:

class HomeController < Controller

  def index
    @message = "Welcome to ASP.NET MVC!"
    view
  end

  def about
    view
  end

end

Views/Home/index.html.erb

<h2><%= html.encode(view_data.message) %></h2>
    <p>
        To learn more about ASP.NET MVC visit <a 
href="http://asp.net/mvc" title="ASP.NET MVC 
Website">http://asp.net/mvc</a>.
</p>


Global.asax:

 public class MvcApplication : RubyMvcApplication
    {

    }








Posted by Ivan Porto carrero (casualjim)
on 2009-06-23 22:10
(Received via mailing list)
it fails much earlier than at the controller. you should never get to 
that
page because that is just plain vanilla asp.net mvc stuff has nothing to 
do
with ironruby mvc.  Have you created an asp.net mvc application
before on your machine? Did that work?

I copied your code to a new project and still it is giving me issues. It
> is not picking up the Routes.rb file



Does that mean the sample does work on your machine?


Also when you make a change to routing etc you have to restart the web
server
---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
Posted by Mohammad Azam (azamsharp)
on 2009-06-23 22:13
yes, I have created ASP.NET MVC application before on my machine and it 
did work.

I have restarted the server but no use!

Your sample does work but it throws some assembly errors. I can avoid 
those errors by going to controller actions.

But, I don't know why it does not work for a new project.

I only see this page:

he resource cannot be found.
Description: HTTP 404. The resource you are looking for (or one of its 
dependencies) could have been removed, had its name changed, or is 
temporarily unavailable.  Please review the following URL and make sure 
that it is spelled correctly.

Requested URL: /home
Posted by Mohammad Azam (azamsharp)
on 2009-06-23 22:15
Is there any web.config setting that needs to be done?
Posted by Ivan Porto carrero (casualjim)
on 2009-06-23 22:17
(Received via mailing list)
did you compile the new project?Can you email me your project so I can 
take
a look.. instead of asking all these questions?
---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
Posted by Mohammad Azam (azamsharp)
on 2009-06-23 22:19
Where can I get your email?
Posted by Ivan Porto carrero (casualjim)
on 2009-06-23 22:21
(Received via mailing list)
ivan at flanders dot co dot nz

---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
Posted by Ivan Porto carrero (casualjim)
on 2009-06-23 22:40
(Received via mailing list)
To make it work I only made 1 change.
I have a debug build of System.Web.Mvc.dll in the sample. I referenced 
that
one and rebuilt then hit F5 to start cassini and it worked

The ironrubymvc dll is built against that debug version so it expects 
that.
I have to fix that at some point
---
Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)
Please log in before posting. Registration is free and takes only a minute.
Existing account (Switch to SSL-encrypted connection)
NEW: Do you have a Google/GoogleMail or Yahoo account? No registration required!
Log in with Google account | Log in with Yahoo account
No account? Register here.