[Ironruby-core] IronRubyMvc Filters and View Helpers

Ivan Porto Carrero ivan at flanders.co.nz
Wed Aug 19 02:10:49 EDT 2009

regarding helpers. You need to open up a class and add your methods there.

module System::Web::Mvc::IronRuby::Helpers

  class RubyHtmlHelper

    def menu_link(text, url, key, route_value_key=:controller)
      if key.to_s.underscore ==
        "<li class='current_page_item'><a href='#{url}'>#{text}</a></li>"
        "<li><a href='#{url}'>#{text}</a></li>"

    def login_menu_link(login_text="Log in", logout_text="Log out",
login_action=:log_on, logout_action=:log_off, controller=:account)
      text, act = view_context.controller.is_authenticated? ? [logout_text,
logout_action] : [login_text, login_action]
      menu_link text, "/#{controller}/#{act}", controller

    def format_chat_body(chat_body)
      encode(chat_body).gsub("\n", "<br />")



You can define filters in multiple ways, and the way you've chosen is only
there for working with legacy filters (legacy as in written in C# :)).

for example to implement the AuthorizationFilter you can do so by
implementing the following class

class RubyAuthorizationFilter < AuthorizationFilter

  def on_authorization(context)
    # put authorization logic here


and then in the controller you do

filter RubyAuthorizationFilter

or you could do it in a more rubyesque way

authorized_action :index do |context|
    # add authorization logic here

from then on that controller requires authorization to get to its actions.
The latter uses the built in AuthorizationFilter too but tucks it away.

If you're curious as to how this works:

Hope this helps

Met vriendelijke groeten - Best regards - Salutations
Ivan Porto Carrero
Blog: http://flanders.co.nz
Twitter: http://twitter.com/casualjim
Author of IronRuby in Action (http://manning.com/carrero)

On Wed, Aug 19, 2009 at 7:36 AM, Shay Friedman <shay.friedman at gmail.com>wrote:

> Hi guys,
> I'm playing with IronRubyMvc, which is just great BTW, and I have two
> issues I'm struggling with - filters and view helpers.
> About filters, I understand that this is done with the filter method which
> receives the method name and filter class. How can I use for example, the
> built-in Authorize filter and give it its initial values (like allowed roles
> or users)? because I need to pass on the name of the class and not an
> instance, I couldn't figure out how to pass the values as well.
> Regarding custom view helpers, is it possible to add those using rb files?
> I've tried to add an rb file to the Helpers folder but it doesn't seem to be
> read from anywhere (I had also added some syntax mistakes and never got an
> exception about them).
> Once again, the IronRubyMvc framework is awesome!
> Thanks!
> Shay.
> ----------------------------
> Shay Friedman
> http://www.IronShay.com <http://www.ironshay.com/>
> Follow me: http://twitter.com/ironshay
> _______________________________________________
> Ironruby-core mailing list
> Ironruby-core at rubyforge.org
> http://rubyforge.org/mailman/listinfo/ironruby-core
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://rubyforge.org/pipermail/ironruby-core/attachments/20090819/4f2d30a7/attachment.html>

More information about the Ironruby-core mailing list