ActionExtension for rails

| No Comments | No TrackBacks
In my rails application i often have this kind of code in my erb/haml files:
There is some repetition in it. Why not infer the i18n-key from the action? My approach:
The parameters should also be passed to the i18n key. So for the first button_to call the translation method is invoked with: _('CommentRating.actions.create',:rating => :good, :comment => @comment)
Some of these ideas are relatively easy to implement:
Requirements:
  • Each model needs an class-method called 'actions'
  • Each model needs an instance-method called 'actions'
  • The actions-methods return an proxy (ActionProxy) that records the method name that is invoked on it (method name = action name)
  • the proxy returns an information object (ActionInformation) that contains:
    1. the instance or the class of the model
    2. the action name
    3. the parameters
  • the ActionInformation has methods that infer the i18n key as well as the url

Now this can be used like this:
Improvements to work on:
  • infer method (:delete etc)
  • dont merge the parameters into the url. make them accessible seperately so they can be extracted and posted via hidden fields inside a form.
  • maybe redefine actions in the models to preprocess the parameters: define_action :rate => lambda{|*params| {:rating => params[1]} }

No TrackBacks

TrackBack URL: http://ragmaanir.mypresident.de/mt/mt-tb.cgi/9

Leave a comment