[Ironruby-core] IronRubyMvc Filters and View Helpers

Ivan Porto Carrero ivan at flanders.co.nz
Sun Aug 23 10:09:45 EDT 2009


You should be able to put the helper files you create in the helpers, that
folder is added to the load path so it should work.ASP.NET
 MVC uses extension methods for its helper classes, when I was
implementing that stuff for IronRubyMvc extension methods weren't
supported yet.

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



On Sun, Aug 23, 2009 at 5:43 AM, Shay Friedman <shay.friedman at gmail.com>wrote:

> 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 <ivan at 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.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
>>>
>>>
>>
>> _______________________________________________
>> Ironruby-core mailing list
>> Ironruby-core at rubyforge.org
>> http://rubyforge.org/mailman/listinfo/ironruby-core
>>
>>
>
> _______________________________________________
> 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/20090823/84a42463/attachment.html>


More information about the Ironruby-core mailing list