Scaffolding: Ignore some property by attribute?

23 views
Skip to first unread message

JakeS

unread,
Oct 31, 2010, 11:03:38 AM10/31/10
to Castle Project Users
I'm using scaffolding to quickly generate a UI around a couple of
activerecord models. But those models have a lot of properties on
them that I don't necessarily want to show in this UI. Is there some
way to have my scaffolding ignore some properties of the model? A
quick scan of the source doesn't seem to show one.

If not, I suppose I could just hack in a quick [ScaffoldIgnore]
attribute, right?

John Simons

unread,
Oct 31, 2010, 7:10:11 PM10/31/10
to Castle Project Users
Jake,

You could override the default templates with your own for this
specific models.
See http://www.castleproject.org/monorail/documentation/v20/integration/arscaffold.html
for how to override templates.
And here for examples of templates:
http://github.com/castleproject/Castle.MonoRail/tree/master/src/Castle.MonoRail.ActiveRecordSupport/Scaffold/Templates/

Cheers
John

JakeS

unread,
Nov 1, 2010, 9:25:23 AM11/1/10
to Castle Project Users
I suppose that's possible, but seems a lot of work. For example, with
the edit.vm I'd either have to design my own UI pretty much from
scratch, or put ugly #if statements all through it to tell it to
ignore the few properties I do not want to show up. Neither approach
feels very appealing.

I could work out my own viewmodel implementation and pass THAT to the
scaffolding, but converting to/from the activerecord entity to the
viewmodel is also looks like a lot of manual work.

It seems to me that putting some sort of attribute on the activerecord
entity would be the simplest move. But that would mean my User model
wouldn't have it's "Ignored" property on any scaffolding it might be
used on in the future.

Maybe adding to the scaffolding attribute itself would work-- some way
to list the properties on the type that will be scaffolded. Or a
callback method for the scaffolding code that would return the
properties that should be used. Hmm.

On Oct 31, 6:10 pm, John Simons <johnsimons...@yahoo.com.au> wrote:
> Jake,
>
> You could override the default templates with your own for this
> specific models.
> Seehttp://www.castleproject.org/monorail/documentation/v20/integration/a...
> for how to override templates.
> And here for examples of templates:http://github.com/castleproject/Castle.MonoRail/tree/master/src/Castl...

John Simons

unread,
Nov 2, 2010, 12:58:20 AM11/2/10
to castle-pro...@googlegroups.com
Hi Jake,

I have started working on an implementation of the same Helper as there is in ASP.NET MVC for MR - see http://bradwilson.typepad.com/blog/2009/10/aspnet-mvc-2-templates-part-1-introduction.html
I've attached my cs file. It is still a work in progress, but maybe this helps.

Cheers
John
ForHelper.cs
Reply all
Reply to author
Forward
0 new messages