On 26 January 2012 14:47, Walter Lee Davis <[email protected]> wrote: > > On Jan 26, 2012, at 9:37 AM, Colin Law wrote: > >> On 26 January 2012 14:26, Walter Lee Davis <[email protected]> wrote: >>> I have a strong handle on when to use a helper -- at least I think so. A >>> helper may include some logic (not enough to belong in the model) and it >>> presents html as its output. So I have a conceptual problem about this >>> solution that I've built: >>> >>> #helpers/people_helper.rb >>> def person_roles >>> (%W(assistant author collector editor foreword illustrator interviewer >>> introduction narrator notes translator) + >>> Role.group('name').map(&:name)).uniq().sort >>> end >>> >>> I use the output in a view, as part of a collection_select picker for a >>> string-based attribute. This picker has a JavaScript "combobox" behavior >>> added to it, so the editor can add new roles to the list at whim. But the >>> output is an array. Does this invalidate my use of a helper method? Or am I >>> thinking too much about the label "helper" here? >> >> To me that looks more like something that should be called in the >> controller and go into an @ variable for use in the view. The general >> rule is setup data in the controller and display it in the view. The >> method itself could go in the Role model or in a module in lib >> >> Colin > > I had it in the controller, but I didn't like the look of having to declare > an instance variable inside each method that needed this (new and create and > edit and update). The helper was there for the asking in each view, so it > seemed DRYer. Is there a way to have my cake and eat it too?
If it is the same code in each action then set the variable in a before_filter in the controller. Then it will be setup for each action that you specify. Bone dry. Colin > > Thanks, > > Walter > > -- > You received this message because you are subscribed to the Google Groups > "Ruby on Rails: Talk" group. > To post to this group, send email to [email protected]. > To unsubscribe from this group, send email to > [email protected]. > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > -- gplus.to/clanlaw -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to [email protected]. To unsubscribe from this group, send email to [email protected]. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.

