This is one of those things that apparently everyone just knows, but I didn’t, and haven’t, for the past 3 months of doing MonoRail development. Color me stupid. Hopefully someone else out there can benefit from this.
If you want to restrict a certain action to only be available via a particular type of http request (POST, GET, etc), all you have to do is add an AccessibleThrough attribute to your action, like so.
[AccessibleThrough(Verb.Post)]
public void Delete(int id)
Yup, that’s it! I started down this path of parsing strings and case insensitive comparisons all the while thinking "This has got to be easier". Turns out it is.
If you’re using Castle Monorail, and trying to use the FormHelper to create a form select janger from an enumerated type, you may or may not be confused as I was. It’s not obvious, and I couldn’t find many good docs, outside of a forum post.
This is how to do it. First, you have to pass the Enum type into your view data (here: MemberRoles).
public void Edit([ARFetch("mid")] MembershipInformation membership)
{
PropertyBag["MemberRoles"] = typeof (MemberRole);
PropertyBag["membership"] = membership;
}
Then you have to wrange with FormHelper. I have a love-hate relationship with FormHelper. It can be really frustrating sometimes. Anyway, here’s the syntax for how to make your select statement.
$FormHelper.Select("membership.MemberRole",
$FormHelper.EnumToPairs($MemberRoles),
$DictHelper.Create("value=First", "text=Second"))
What FormHelper.EnumToPairs does is create an array of Pair<int, string> objects. The Pair<> object has 2 properties, First, and Second. First, in this case, is an integer with the enum value, Second is a string of the enum’s name. So you pass that bad boy into your FormHelper as the array of select thingies, and then tell it to use the "First" property as the value of the select and the "Second" as the text to display.
Magic! Painful, painful magic! Maybe I should write my own FormHelper.EnumSelect thing. Hrmm…
Found another Castle ActiveRecord/NHibernate gotcha today.
I had string columns being noisily truncated in my ActiveRecord types. Grr. I google and find a solution in the ActiveRecord FAQ: add a ColumnType="StringClob" to the property attribute.
[Property(ColumnType="StringClob")]
public String Contents
{
get { return _contents; }
set { _contents = value; }
}
Silly me though, I expected that to actually work as advertised. It doesn’t.
When you use ActiveRecord to create your schema, it will create the above column as a NVARCHAR(255). OMGWTFBBQ?!
The solution is to add an SqlType = "NTEXT" to your attribute as well. Mmm, cryptic.
[Property(ColumnType = "StringClob", SqlType = "NTEXT")]
public string Description { get; set; }
Please refer to the following for further discussion of the issue.