Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>Check out the <a href="http://en.wikipedia.org/wiki/Law_of_Demeter" rel="nofollow">Law of Demeter</a>. It explains why what you're doing is causing problems (no separation of concerns = spaghetti code). Also check out <a href="http://www.simonecarletti.com/blog/2009/12/inside-ruby-on-rails-delegate/" rel="nofollow">ActiveSupport::Delegate</a> to see how you can concisely apply the Law of Demeter to your Rails app and avoid lists of boring getters and setters.</p> <p>A few notes to help you out:</p> <ol> <li>Make all your ActiveRecord calls like <code>where</code> in your controller. Your view should have arrays (or ActiveSupport::Proxy's) to simply iterate over and display. You should avoid having your view trigger database queries, and you should never keep record-fetching business logic in them.</li> <li>Rather than chaining endlessly on your model associations, define or delegate methods from one model to another. For example, instead of <code>@comment.post.title</code>, define and use <code>@comment.post_title</code> instead (note the underscore). This avoids requiring your view to have innate knowledge of your database schema and model associations. It simply needs to know that a comment has a post title, however that data is modeled.</li> </ol> <p>If you refactor your code to keep each model focused on a single concern and modeling a single resource, then layer the associations on top of that in a clean, compartmentalized fashion, you will surely obviate the need for someone to solve this single question for you (teach a man to fish…).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload