Skip to content

Instantly share code, notes, and snippets.

@jdickey
Last active December 15, 2015 23:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jdickey/5344110 to your computer and use it in GitHub Desktop.
Save jdickey/5344110 to your computer and use it in GitHub Desktop.
-# As generated
%h1 Listing contributions
%table
%tr
%th
%th
%th
- @contributions.each do |contribution|
%tr
-# Note that `contribution` is treated as a top-level resource. It's not. Hilarity ensues.
%td= link_to 'Show', contribution
%td= link_to 'Edit', edit_contribution_path(contribution)
%td= link_to 'Destroy', contribution, :method => :delete, :data => { :confirm => 'Are you sure?' }
%br
= link_to 'New Contribution', new_contribution_path
-# After corrective R&D
%h1 Listing contributions
%table
%tr
%th
%th
%th
- @contributions.each do |contribution|
%tr
-# Since Contributions are nested within Articles, they cannot be referenced without
-# also referencing the Article to which they are attached.
%td= link_to 'Show', article_contribution_path(contribution.article, contribution)
%td= link_to 'Edit', edit_article_contribution_path(contribution.article, contribution)
%td= link_to 'Destroy', article_contribution_path(contribution.article, contribution), :method => :delete, :data => { :confirm => 'Are you sure?' }
%br
= link_to 'New Contribution', new_article_contribution_path(@contributions.first.article)

Want to know how brain-dead the scaffolding generator for Rails is? Mind-bogglingly so.

The first of the two files below is what was generated for app/views/contributions/index.html.haml; the second is the corrected version. Bear in mind that the routing had already been adjusted prior to running the generator so that it could have determined that Contributions were nested within Articles, if it had cared to. The generator either didn't look or couldn't deal with nested resources. Either way, serious brain death taking significant time to detect, diagnose and work around was required.

There has to be a better way. Any ideas?

EDIT: Investigating amatsuda/nested_scaffold as more likely to be Useful. nested_scaffold is currently at an 0.2.3 release. Being pre-1.0 (as are many of the Gems we rely on, but that's another rant entirely), it can't be expected to yet be feature-complete, let alone bug-free. Support for RSpec is listed as a known issue. One of the major items on my "after we get staffed" to-do list is going through and systematically evaluating all pre-1.0 Gems we rely on. If there are more mature alternatives, let's see what the pros and cons of moving are. If there aren't, what outstanding issues blocking 1.0 are pain points for us? (Maybe a more fully-staffed Meldd.com could help out and get some community cred in the process.) But also, as we see here, post-1.0 status is not a universal indicator of ideal fit to our needs; RSpec itself currently sits at 2.13.something and Rails itself is at 3.12.something -- both more than mature enough for most shops to rely on.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment