Ruby on Rails Tuesday, March 25, 2014

On 24 March 2014 22:48, Dave Castellano <lists@ruby-forum.com> wrote:
>>
>> Do not make us wade through lots of code trying to understand what is
>> going on. Explain the problem and show us just a few lines of code if
>> necessary. For instance of what type is play_list? You said it was
>> an instance of a model, but it seems to be an array or collection of
>> some sort.
>>
>> Colin
>
> Sorry about that :-)
>
> Play_list is an array of arrays returned at the beginning of the create
> method. Each array contains a topic id. Array[0] needs to be converted
> to a list of the question id's contained in that topic. That is all
> taken care of.

That sounds to me like a horrible way to organize data, it is
generally much better to deal in records and associations rather than
extracting id values and manipulating them. However, if you feel you
must do it that way...

>
> The sequence of the question id's in array[0] needs to be manipulated,
> in more than one method.
>
> So... I need to either duplicate the code in several methods (in the
> same controller) or create a method that is called by the controllers
> multiple methods. The model method seems right but play_list does not
> seem to be an instance as it is not yet created and is not yet an
> attribute of the model

You could either have a private method of the controller, or a class
method of the model (rather than an instance method). Probably the
latter.

Colin

--
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe@googlegroups.com.
To post to this group, send email to rubyonrails-talk@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/CAL%3D0gLuhD3qeeCfkizTMM%3D8AuNHA1puVn86xAMgSBgLNhyQROw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment