Acts as ASP.NET (a Rails Plugin)
Posted 3 months ago by jacques | 39 comments
As a former ASP.NET developer of nearly 5 years, I sometimes find myself really missing some of its unique features after going a year and a half exclusively in the Rails camp. So as of April 1st 2008, I have finally provided a Rails plugin that the world has been waiting for.
# presenting...
acts_as_aspdotnet
script/plugin install http://actsasaspdotnet.googlecode.com/svn/trunk/acts_as_aspdotnet
Feature 1: Viewstate (and more!)
Viewstate is back. Now new and improved on top of Rails. acts_as_aspdotnet overrides form_tag to put back the hidden input field that contains loads of crucial processing data on every postback that will fill your server pipes with more glorious bandwidth:
Your old boring Rails Form…
<form action="/people" class="new_person" id="new_person" method="post">
<p>
<b>Name</b><br />
<input id="person_name" name="person[name]" size="30" type="text" />
</p>
<p>
<b>Email</b><br />
<input id="person_email" name="person[email]" size="30" type="text" />
</p>
</form>
Can now look like this:
<form action="/People/Default.aspx" class="new_person" id="new_person" method="post">
<input id="__EVENTTARGET" name="__EVENTTARGET" type="hidden" value="" />
<input id="__EVENTARGUMENT" name="__EVENTARGUMENT" type="hidden" value="" />
<input id="__VIEWSTATE" name="__VIEWSTATE" type="hidden" value="/XtplIo7SVYvjZC8ffNqtkHIhP5TdNKRLNnFL5mTJuprao/NDMrAzOXmYnpUv56K0gBNK+sN0yT5EJsxU+BtzhGUEb6Pmn5u1wGQHm4ntORTpCZ1mPGkaiVTa7IriLjWzFvuGUmBw4VEx1jPcoZEfjqMrnQNNIeZHO5JnCBGIilLWCVPURBYUXO6UkEXI3GOhfoPDi3tRwEbWr7dva4IFMyE/QqAAzAnZABgBmwHq5oQQGNnB0Gu9xPoLH9IXHHUPF8u+D2/VJziirP55sQXXTw15Al1i2ygzMmG5Zl2a3N2KA9pW5Z5ZFzNZ+gtEo3d/DcRizf/wuo1i+JUIEG2s5leEtnY5AT5vxqI5kbxVAViIV8pQoxYuaTQVTxGnohaU6hqrGPMixaOdKkEoe/lvzXOYbe+v7vqug2Of/VxXX7HzOEGgf8hShTLM9LCBWAAa3ePOEuAyyIZiGSnHv9BEq3MJaQ+LPxwxtcREGA422zvZg9z79VY1/WpvGe5lac+fUyoSIGaZBamGWDkpuomONKCHwv+XdYGNnpJDSj8tcYrigsR/oVtI6hkEygfKV/GTdiQLawjaUmKvnxyTLQ5cgs6jbuOC21lQcb68SkVH0h3EDyx6PCn3tkg4+BgVfm/hOj4U1520V81VVPoJLnmuTrhUZ+GRvbTR7btLYWqCUozv2Da9yROdQmUGD6PohHm+/es3kSQLgXH+EWYee9EaHW2dyTNm46YhRVuHgbCHkko5kI+7bwyNmtrUT70h2OqOYFiU2whPf0z7e9iK3OxfuCqxV8vW1MULKv4QldC6sla/ZQ1HdlxBr/wwvTIEQkN6bCm92DgKEQNZT5T+W5pQV2NHugb9p/d2VFN+poEvet3nNvq5693qsgOR7BOxiXIc2vhDmI7KkB/iXos6obvs/X+WX1llJkgzfCezhlNCTBoBheGhy69cGz8doRxqzId9BFdaI8Y4Ng+HgRgFLWcqdEat34dv2OzhxSJn4Svv=" />
<p>
<b>Name</b><br />
<input id="Page11__ctl1_person_name" name="person[name]" size="30" type="text" />
</p>
<p>
<b>Email</b><br />
<input id="Page12__ctl8_person_email" name="person[email]" size="30" type="text" />
</p>
</form>
Feature 2: Beautiful Error Pages
ASP.NET error pages are really quite remarkable. They give you a nice succinct way of telling visitors that your site is broken, and you just don’t give a flying …..
Now you can recreate that magic whenever your Rails application throws an exception. acts_as_aspdotnet overrides all 3 error pages to look unmistakably ASP.NET.
Feature 3: Validator Controls
Hate validating each of your form input fields only once? DRY is not the ASP.NET way. Now we have a much better alternative.
Declare your validators on the page itself, just like in ASP.NET.
<%= text_field_tag :name %>
<%= required_field_validator_tag :name %>
<!-- also works as part of a FormBuilder -->
<%= f.text_field :email %>
<%= f.required_field_validator :email %>
<%= f.regular_expression_validator :email, '\w+([-+.]\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*', "Bad Email Address!" %>
<%= f.text_field :email2 %>
<%= f.compare_validator :email, :email2, "Emails must match!" %>
Validators, now with AJAX! Minus the A, A, and X.
Included is also an override to submit_tag which uses that wonderful __doPostBack to submit the form.
It all works just like you remember from ASP.NET, with the framework making forms so much easier, by taking away your control and replacing it with perfectly non-unobtrusive javascript.
Feature 4: URL Overhaul
A web application isn’t an ASP.NET application unless it has the right extensions. After installing this plugin, all your resources will automagically be turned into proper, universally respected urls that all end in .aspx.
If you have this in your routes:
map.resources :people
Your site will all of a sudden start using new and improved urls for all its forms.
/People/Default.aspx => PeopleController::index
/People/Default.aspx (POST) => PeopleController::create
/People/1/Show.aspx => PeopleController::show
/People/1/Show.aspx (PUT) => PeopleController::update
/People/1/Show.aspx (DELETE) => PeopleController::destroy
/People/New.aspx => PeopleController::new
/People/1/Edit.aspx => PeopleController::edit
The url helpers are also updated accordingly.
people_url #=> /People/Default.aspx
people_url, :method => :post #=> /People/Default.aspx
new_person_url #=> /People/New.aspx
@person = Person.find(1)
person_url(@person) #=> /People/1/Show.aspx
person_url(@person), :method => :delete #=> /People/1/Show.aspx
person_url(@person) :method => :put #=> /People/1/Show.aspx
Feature 5: Elegant Meta Tags
Give those search engines the meta tags they are really craving for.
Just call:
<%= aspdotnet_includes %>
in your head tag and you’ll generate something that might look just like this.
<meta name="vs_showGrid" content="False">
<meta name="GENERATOR" Content="Microsoft Visual Studio 7.0">
<meta name="CODE_LANGUAGE" Content="C#">
<meta name="vs_defaultClientScript" content="JavaScript">
<meta name="vs_targetSchema" content="http://schemas.microsoft.com/intellisense/ie5">
Also, don’t forget to add your MS_POSITIONING attribute to the body tag with GridPositioning for an even more authentic ASP.NET experience.
Feature 6: Element ID Obfuscation
Hate when your html tags have IDs that let you access them in a deterministic way in javascript? Well, Microsoft has just the solution for this. I’ve gone ahead and emulated everyone’s favorite feature of ASP.NET, giving elements nondeterministic ids such as the lovely page00_ctl00_userEmailAddress.
There’s no better way than this to put the fun back into writing Ajax applications.
<%= text_field :person, :name %>
Instead of generating this:
<input id="person_name" name="person[name]" size="30" type="text" />
Our field now expands out to the much more substantive:
<input id="Page17__ctl3_person_name" name="person[name]" size="30" type="text" />
Much clearer.
If you still insist that you must have normal id, no problem. Microsoft has delivered a perfect solution with “ClientID”, which I have replicated here to the best of my abilities. Just call client_id(:person_name) and you’ll get the runtime generated client_id of your control. This comes in very handy in building ajax applications.
$("<%= client_id(:person_name) %>")
Or you can set a non server control element on the page. This was an extremely useful technique I discovered years ago on the ASP.NET forums.
<input type="hidden" id="person_name_id_holder" value="<%= client_id(:person_name) %>" />
Now whenever you need the id of the element at runtime, just use this.
$("person_id_holder").value // => Page05_ctl01_person_name
This way you can go back to putting your javascript code in external files where it belongs. Very nice.
I Want This Plugin Right Now
There you have it. A plugin that will give you fond memories of earlier years when web development was more interesting, fun, and satisfying.
Now you just have to install it.
script/plugin install http://actsasaspdotnet.googlecode.com/svn/trunk/acts_as_aspdotnet
You can also grab the sample project that contains a fully functional ASP.NET on Rails application used in these examples. Just unzip, migrate, and go.
Host it and send the link to your boss or a coworker (preferably one who’s as sharp as a bowling ball). Tell them you built it with ASP.NET and dare them to disagree.
Possible Real World uses for acts_as_aspdotnet
- Trying to sell your startup to Microsoft
- Pranking your offshore development team
- Personal Nostalgia
Combine this plugin with acts_as_enterprisey for a distinctly synergistic effect.


You, sir, are a hero among mortals... well done.
April's Fool, right? :-)
Funny!
Good thing the new ASP.NET MVC engine is being worked on... In a year or so, you'll be able to write IronRuby ASP.NET MVC web apps.
Very nice, but a more deadpan approach would be better, I think. You have to write it like you really think it's a good idea.
That said, this the best RoR April Fool's I've seen. Well done!
///ark
Hahaha ... Very nice!
And I see you actually did write the code too... talk about thorough
Thanks alot. This got around to my boss, and within half an hour, and some young, hip looking Rails dude was at my desk asking me how to reconfigure my chair while I was packing my things :)
I nominate this to be checked into Rails Core.
If you stand back and squint your eyes, acts_as_aspdotnet morphs into acts_as_despondent
Definitely some good stuff here. I'm going to try it out on
an app I'm working right now.
Good April Fool joke...
but if it is not, great work! you have totally and completely ruined the beauty of rails.
and the most important feature...and it runs 1million times faster than barebone rails...
Hi Sherlock. That feature is currently planned for 2.0.
[wipes nostaligic tears from his eyes]
so many memories...
Just glorious, reminds me of what I'm missing since jumping ship from ASP.NET to Rails.
Sorry I need some help - I can't seem to get it to work under Visual Studio. Help!
Hahaha,
As a brand new RoR developer and still a .net experienced developer, it's very funny. :-)
All of the uglyest part of .net is available thru that plug-ins.. I really need it ;-p
I'll be able to develop site much faster and let the boss impression i'm still doing it in .net ;-p
Oh, this is a great start. I'd like to see code-behind classes in next year's version. Can I also get a runat="server" added to every dynamic tag?
Very nice!
(acts_as_enterprisey author) Ha! Love it.
You've clearly put a lot of time into recreating ASP.NET. You must really miss it.
there's another plugin:
acts_as_DHH_ass_kisser
I can only say... Awesome!
Thanks! Reminds me of why ASP.NET MVC is so great.
Brilliant! Thank you! :-D
You're missing feature #7: make your worthless framework half as stable as ASP.NET so that it can handle half of the workload without shitting itself and assraping the end users (allow me to point to Twitter and Gravatar as pitiful examples of your unstable, joke of a platform).
I think it's time for you to uninstall the act_as_dhh_douche plugin.
I'm really late to this, but oh my god this is so funny!!!
I hope Scott Guthrie has read this post.
pamment based shuttleheaded unflexibly mancipatory fervidness duologue clearwing
US Chess Federation: Players Gallery: WGM Angelina Belakovskaia
http://www.cnn.com/WEATHER/9803/30/minnesota.tornadoes/index.html
pamment based shuttleheaded unflexibly mancipatory fervidness duologue clearwing
Riteway Electric & Construction Services
http://www.topix.com/city/ary-ky
LOL. simply beautiful. a few nice touches would've been:
* require compilation for any changes to code
* ADO.NET-like interface for ActiveRecord, with out old friends DataTable, DataReader, Connection, DataAdapter, and all the rest
* an IDE for Rails that freezes atleast 3 times a day
* a WYSIWYG HTML designer that turns all of your XHTML into old-school IE-compatible HTML everytime its used
... there are so many other things I miss!! :P
pamment based shuttleheaded unflexibly mancipatory fervidness duologue clearwing
Yakudo
http://www.architecturaldesign.co.za/
pamment based shuttleheaded unflexibly mancipatory fervidness duologue clearwing
Reviews for Buffy's Third Season
http://www.angelfire.com/ri2/syrus/
[URL=http://www.estatico.cn/cuoco-it] cuoco it [/URL] cuoco it [URL=http://www.estatico.cn/albergo-all-isola-d-elba] albergo all isola d elba [/URL] albergo all isola d elba [URL=http://www.estatico.cn/presa] presa [/URL] presa
pamment based shuttleheaded unflexibly mancipatory fervidness duologue clearwing
Pacesetter Graphic Service
http://www.outdoorontario.net/hunting/
pamment based shuttleheaded unflexibly mancipatory fervidness duologue clearwing
Studio Prima
http://www.carolritz.com/
pamment based shuttleheaded unflexibly mancipatory fervidness duologue clearwing
Rotary Club of Barcaldine
http://www.fortwilliamfishing.com
Meno http://www.rkentertainer.com/outlook quando [URL=http://www.rkentertainer.com/montale] in montale [/URL] molto, [URL=http://www.rkentertainer.com/videocamera-hdv] videocamera hdv suoi [/URL] era.
Nice Site!
http://google.com
..was just passing by.. good work http://www.camerette-per-ragazzi.nceatracker.com
Nice Site!
http://excellent-credit-card.blogspot.com
sto andando dire ai miei amici circa questo luogo - ? solo perfetto! http://www.lettore-dvd-panasonic.nceatracker.com