Ruby on RailsvsASP.NET MVCSandroPaganottiSoftware Architect, Wave Factoryhttp://sandropaganotti.com/Twitter: @sandropaganottiSimone ChiarettaWeb Architect, Council of the EUhttp://codeclimber.net.nzTwitter: @simonechMilano, 19 Febbraio 2011
Join the Conf: theapp
Conference List
AttendeeRegistration
Join the Conf: themaking
The Model
Project Setuprails new join_the_conf -d mysqlcd join_the_confmate config/database.ymlrakedb:createrails server[File>New Project>ASP.NET MVC 3 Application]
InstallDependenciesmate Gemfilegem 'devise'gem 'rails_admin', :git => '...'gem 'haml‘bundle installInstall-Package MvcScaffolding
Create Modelrails generateresourceConferencename:stringdescription:textstart:dateend:datelocation:stringcapacity:integer -a indexpublic class Conference { public int Id { get; set; } public string Name { get; set; } public string Description { get; set; } public DateTime Start { get; set; } public DateTime End { get; set; } public string Location { get; set; } public int Capacity { get; set; } }
Create BackOfficerails generaterails_admin:install_adminAdministratorrakedb:migraterails serverhttp://localhost:3000/adminScaffold Controller AttendeeScaffold Controller Conference[Build]http://localhost:2246/Admin/Conference
Validationclass Attendee < ActiveRecord::Basebelongs_to :conferencevalidates_presence_of :conference_id,:name, :emailvalidates_uniqueness_of :email,:scope => :conference_idend public class Attendee { public int Id { get; set; } public intConferenceId { get; set; } [Required] public string Name { get; set; } [Required] public string Email { get; set; } virtual public Conference Conference { get; set; } }
Routingresources "conferences",:only => [:index] doresources "attendees",:only => [:index, :create]Endrake routespublic class ConferencesController : Controller public ViewResult Index()public class AttendeesController : Controllerpublic ViewResult Index()public ActionResultCreate(Attendeeattendee)
Controllerclass ConferencesController ...def index@conferences = Conference.all(:order=>'start DESC')endendpublic class AttendeesController : Controller{privateJTCContextcontext = new JTCContext();	public ViewResult Index()	{	return View(context.Attendees.ToList());	}}
Layout!!! 5%html%head%titleJoin The Conf= stylesheet_link_tag :all= javascript_include_tag :defaults= csrf_meta_tag%body= yield<!DOCTYPE html><html><head> <titleJoin The Conf</title> <link href="@Url.Content("~/Content/frontend.css")" rel="stylesheet" type="text/css" /> <script src="@Url.Content("~/Scripts/jquery-1.4.4.min.js")" type="text/javascript"></script></head><body> <h1>Join The Conf</h1> @RenderBody()</body></html>
Viewsconferences/index.html.haml%ul= render @conferencesconferences/index.cshtml<ul>@foreach (Conference item in ViewBag.Conferences){ @Html.Partial("_conference", item)}</ul>
Partial Viewsconferences/_conference.html.haml%li = "#{conference.name} - #{conference.start}"= link_to '(show attendees)',conference_attendees_path(conference)conferences/_conference.cshtml<li>@Model.Name: - @Model.Start @Html.ActionLink("(Register)","New","Attendees")</li>

Ruby on Rails vs ASP.NET MVC