Hi Ivan, Is it possible to put the RubyHtmlHelper code in a file under the Helpers directory?
Another MVC question - I tried to use alias_action but couldn't get it to work. I also tested it on the sample Mvc project (HomeController uses it - alias action :my_method, :index_again) without success as well. Thanks for the help! Shay. On Wed, Aug 19, 2009 at 9:10 AM, Ivan Porto Carrero <i...@flanders.co.nz>wrote: > 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 == > view_context.route_data.values[route_value_key].underscore > "<li class='current_page_item'><a href='#{url}'>#{text}</a></li>" > else > "<li><a href='#{url}'>#{text}</a></li>" > end > end > > 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 > end > > def format_chat_body(chat_body) > encode(chat_body).gsub("\n", "<br />") > end > > end > > end > > 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 > end > > end > > 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 > end > > 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: > http://github.com/casualjim/ironrubymvc/blob/79efbd0f5baf52d3fbfe8f21a0349d6343dc994b/IronRubyMvc/Controllers/controller.rb#L173 > > 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.fried...@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@rubyforge.org >> http://rubyforge.org/mailman/listinfo/ironruby-core >> >> > > _______________________________________________ > Ironruby-core mailing list > Ironruby-core@rubyforge.org > http://rubyforge.org/mailman/listinfo/ironruby-core > >
_______________________________________________ Ironruby-core mailing list Ironruby-core@rubyforge.org http://rubyforge.org/mailman/listinfo/ironruby-core