On Sunday, June 28, 2015, Federicko <[email protected]> wrote:

> Hi All,
>
> [snip]

> As mentioned, I am new to RoR so I don't know if I'm doing this correctly
> according the Rails convention but the code is working great so I'm happy
> about that.
>
> If someone can review my code please and tell me what I can improve on,
> that would be great.
>
>
In addition to what Colin has pointed out, I'd also move the code for
updating an object's rank into the model - it will make your controller
much simpler and also make it easier to test. You could probably also take
the opportunity to reduce some of the duplication in the rank up/down
method.

On a substance rather than style issue, you don't handle some of the edge
cases, such as what if there is no next article?

The only other real issue is that if two people try to update 2 objects at
the same time there is a chance that the 2 updates will clash and you could
end up with duplicates or gaps - in a toy app like this, largely a
theoretical concern, but worth at least understanding that it could happen.


I'm also thinking there might be an existing gem or something that I can
> install that will do the ranking for me automatically.
>
>
acts_as_list handles most if not all of this. You'll probably learn more
rolling your own though!

Fred


> Anyway, look forward to your feedbacks.
>
>
> Thanks in advance.
>
> --
> 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 [email protected]
> <javascript:_e(%7B%7D,'cvml','rubyonrails-talk%[email protected]');>
> .
> To post to this group, send email to [email protected]
> <javascript:_e(%7B%7D,'cvml','[email protected]');>.
> To view this discussion on the web visit
> https://groups.google.com/d/msgid/rubyonrails-talk/73894ed9-0292-469d-9741-534e50917f04%40googlegroups.com
> <https://groups.google.com/d/msgid/rubyonrails-talk/73894ed9-0292-469d-9741-534e50917f04%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
> 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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/rubyonrails-talk/CABp077V3OgRHxp41AAwiLL3Qe%3D9WfDtnx94G%2BEBB0v3cq6u8Mw%40mail.gmail.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to