Ruby on Rails Monday, August 31, 2015

On 30 August 2015 at 23:27, venu madhav chitta
<venu.chitta1992@gmail.com> wrote:
> No they just use existing tables, do some joins and generate the item
> recommendations. Their interface looks like: recommendations(user_id) and
> returns [item_id]

First if you are using joins manually then it may be that you have
specified the associations incorrectly as it should only rarely be
necessary to specify the joins. In addition you said in the original
post that you were using sql to query, this is almost certainly not
right unless you are doing something rather complex that the rails
activerecord interface will not handle. If you want advice on that
then ask a separate question showing the query you are performing.

So if I understand correctly you have some code that references
several tables but it does not seem appropriate to just put the code
inside one of the models. In such situations I would either make it a
model which is not derived from ActiveRecord or put it in a module in
lib. Whichever seems most appropriate. Probable a model in your
case. Don't get stressed over exactly where you put things however,
there are no hard rules, just do whatever seems most appropriate for
your case.

Colin

>
> On Sunday, August 30, 2015 at 1:03:20 AM UTC-7, Colin Law wrote:
>>
>> On 30 August 2015 at 04:36, venu madhav chitta
>> <venu.ch...@gmail.com> wrote:
>> > I am implementing strategy pattern in Rails where I have Models like
>> > User,
>> > Item, Category and need to recommend items for the users depending on
>> > various algorithms (strategies) that user selects in view.
>> >
>> > I am having a Recommend class which has an interface of
>> > recommend(user_id,
>> > strategy) and returns array of item_id. The strategy in recommend will
>> > be
>> > decided at runtime depending on the option user selects in the view. I
>> > have
>> > placed the recommend interface in /lib directory and the strategies in
>> > /lib/strategy directory. The strategies or algorithms right now will do
>> > SQL
>> > queries to give recommendations which is naive.
>> >
>> > I want to make sure if I placed the files in proper directories or
>> > Should I
>> > need place the recommend class and all the strategies in models or
>> > app/services or any other?. I am really confused.
>>
>> Are there database tables behind the recommend and strategy code or
>> are they just code?
>> You say there are Items but have not told us what an Item is.
>>
>> 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/c9c746c9-2957-49a3-a9ba-f52aa7ae61ec%40googlegroups.com.
>
> For more options, visit https://groups.google.com/d/optout.

--
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%3D0gLuQfst00gVt3eFAPRBG8ALjpVx2p_GM%3DgDe97865XFpqQ%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment