Ugly and cool! Nice trick :D.

El 04-12-2014 a las 17:19, Stefan Haslinger escribió:
> Hi folks!
> 
> Disclaimer: This is an ugly hack.
> 
> I customer wanted to hard override the state value in an Hobo Lifecycle
> without running the action.
> Hobo protects this by setting :state as an protected attribute.
> 
> I was almost ready to remove the life cycle all together, but ... read on!
> So even setting 
> 
>     class Category < ActiveRecord::Base
> 
>       hobo_model 
> 
>       ... 
> 
>       attr_accessible :state 
> 
>  
> wouldn't help, unless - and that's the dirty part, you remove :state
> from attr_protected by
> 
>       Category.attr_protected[:default] =
>     Category.attr_protected[:default].subtract(["state"])
> 
>     end 
> 
> 
> at the very end of the model declaration.
> Then it's pretty straight forward to get a drop down in the edit view:
> 
>     <extend tag="form" for="Category">   
> 
>       <field-list: fields='... state...'>
> 
>           <state-view:>
>               <select-menu  name="category[state]"
>                                      
>     options="&Category::Lifecycle.states.*[0].map {|state|
>     [I18n.t('activerecord.attributes.category.lifecycle.states.' +
>     state.to_s), state.to_s] }" />
>           </state-view:>
> 
> 
> If you don't care about translations, the options are just
> 
>                                    
>      options="&Category::Lifecycle.states.*[0]" />
> 
> 
> It's ugly, but it saved me some hours and I can use the transitions in
> the application as usual.
> 
> Ciao,
> Stefan 
> 
> -- 
> You received this message because you are subscribed to the Google
> Groups "Hobo Users" group.
> To unsubscribe from this group and stop receiving emails from it, send
> an email to [email protected]
> <mailto:[email protected]>.
> To post to this group, send email to [email protected]
> <mailto:[email protected]>.
> Visit this group at http://groups.google.com/group/hobousers.
> For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups "Hobo 
Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/hobousers.
For more options, visit https://groups.google.com/d/optout.

Reply via email to