Ruby on Rails Wednesday, July 1, 2015

On 1 July 2015 at 09:33, Federicko <fedomain@gmail.com> wrote:
> Yeah, I will check that gem out.
> I basically wanted to do this to learn the ways of the Rails :p

In that case I would have two member methods rankup and rankdown that
do everything, including saving, all wrapped in a transaction.

So controller code is just something like
@this_article = Article.find(params[:id])
if params[:rank] == 'up'
@this_article.rankup
elsif params[:rank] == 'down'
@this_article.rankdown
else
# cope with this error appropriately
end

Then you have moved everything that needs to know how ranking works
into the model, while the controller deals with parameters.

Within the model the up/down might be performed using a class method
swap_rank( article_1, article_2 ) with rankup and rankdown finding the
articles affected.

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/acd8dac8-a5a2-4b8f-abfc-3e72ad12b255%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%3D0gLu0_YjKt0LOGm9xVL-UYaiM16dpYV94hdnehrYZBX66bA%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment