I have the need to use custom views for scaffolded controllers (for localisation). I first created an empty list.vm in Views/MyModelName/, which gave me empty content in the layout, just as expected. I then looked into Castle.MonoRail.ActiveRecordSupport/Scaffold/ Templates and copied *.vm into Views/MyModelName/. I had to add PresentationHelper as a helper in the controller, and changed $Form to $FormHelper and $Form.TextHelper to $TextHelper, and localised stuff. It worked well, for the list view, but other views just keep using the assembly embedded ones.

I then took a look at source code in Castle.MonoRail.ActiveRecordSupport/Scaffold/ action files. Here's the result:

protected override string ComputeTemplateName(IControllerContext controller)
{
        return controller.Name + "/list";
}

protected override string ComputeTemplateName(IControllerContext controllerContext)
{
        return controllerContext.Name + "\\create";
}

protected override string ComputeTemplateName(IControllerContext controller)
{
        return controller.Name + "\\confirm";
}

protected override string ComputeTemplateName(IControllerContext controller)
{
        return controller.Name + "\\edit";
}

protected override string ComputeTemplateName(IControllerContext controller)
{
        return String.Format(@"{0}\new{1}", controller.Name, Model.Type.Name);
}

protected override string ComputeTemplateName(IControllerContext controller)
{
return String.Format(@"{0}\{1}removed", controller.Name, Model.Type.Name);
}

protected override string ComputeTemplateName(IControllerContext controller)
{
        return controller.Name + "\\update{1}";
}

So I guess the reason why only list works is rather clear. Besides, the failing ones still fail to use local versions instead of embedded ones even if I name them according to the patterns given, and the behavior is the same regardless of the OS (MacOSX and Windows XP tested). What's more there's a bit of discreptancy here, with create being the only one calling controllerContext.Name, some using string concatenation, others using String.Format (both with various orders and parameters), and update being simply broken with its remaining placeholder.

Therefore may I suggest the simplest fix possible of naming them like the list one, unifying all of them in the process? Or did I miss something along the way?

        return controller.Name + "/list";
        return controller.Name + "/create";
        return controller.Name + "/confirm";
        return controller.Name + "/edit";
        return controller.Name + "/new";
        return controller.Name + "/remove";
        return controller.Name + "/update";

TIA

-- Loic

Attachment: smime.p7s
Description: S/MIME cryptographic signature

Reply via email to