So I got moved onto a Rails project recently, and I see a lot of this:
def set_sub_nav
@sub_nav_list = []
@sub_nav_list << {
:title => 'example',
:slug => 'example',
:url => gen_nav_url(routes_helper: 'example', options: {:categories => 'example'})
}
@sub_nav_list << {
:title => 'example',
:slug => 'example',
:url => gen_nav_url(routes_helper: 'example', options: {:categories => 'example'})
}
@sub_nav_list << {
:title => 'example',
:slug => 'example',
:url => gen_nav_url(routes_helper: 'example', options: {:categories => 'example'})
}
end
Pretty much in most controllers, this feels really bad…just to sanity check, this would be better extracted out into an object? I was thinking of creating a class, and allow it to be configurable on the amount of sub nav entries needed as well as the content. Is this the best way forward?
Beyond that there are also loads of objects(arrays and hashes mostly) set up in classes(mostly controllers). Often these object don’t really corrrespond to the class, like setting a Player object in the team class for instance, once again, would it be much better to extract that out into its own class?
Mostly just wanting some good suggestions, maybe some of you guys have seen a lot of this before coming onto projects where developers had not had much experience with Ruby and or Rails.
Jean