Godzilla74
Godzilla74

Reputation: 2512

The Ruby on Rails Way (guidance)

I'm making a RoR app that is going to have a bunch of network diagnostic tools in it, like ping, traceroute, whois, etc. It's an internal company thing. Being that I'm learning Rails, I'd like to create it in that.

So, I'm curious what's the best structure to make this? Would it make sense to have all the tools under one MVC, like 'tools', or to break each one out into their own MVC (i.e., ping_controller & model/ping, traceroute_controller & `model/traceroute', etc.)?

So:

App
|--models
|  |--tools (which would just write the `ip`, `tool_type` and `hitcount` to the DB.)
|
|--controllers
|  |--tools (which would contain the methods: `ping`, `traceroute`, etc.)
|
|--views
   |--tools
      |--index.html.erb (which would have the individual form to run a given tool and show results)

Or would it make more sense to break it out more, but still keep the individual tool form elements on the same page and direct them with something like form_for(controller: 'ping', action: 'show'):

App
|--models
|  |--ping (which would just write the `ip` and `hitcount` to the DB.)
|  |--traceroute (which would just write the `ip` and `hitcount` to the DB.)
|
|--controllers
|  |--ping (which would contain the normal CRUD and results)
|  |--traceroute (which would contain the normal CRUD and results)
|
|--views
   |--tools
      |--index.html.erb (which would have the individual form to run a given tool and show results)

What's the "Ruby Way" to do this? I feel like the second option is not very DRY, but I'm still learning... hence my question.

Upvotes: 1

Views: 58

Answers (1)

Yang
Yang

Reputation: 1923

If type is the only difference between each types of tools, I would suggest you to use the first way. If there will be more complex logic/columns differences, I would suggest you to have a look into Single Table Inheritance (STI):

http://samurails.com/tutorial/single-table-inheritance-with-rails-4-part-1/

Upvotes: 1

Related Questions