Lighthouse has a new layout. Prefer the old one? Return to the old layout, and switch back any time from the link at the top of each page.

This project is archived and is in readonly mode.

Problems with scaffolding of subclasses

#2156

In 2.3.1(RC2), when generating scaffolding such as:


ruby script/generate scaffold Foo::Bar

... a behavioral mishmash occurs. Specifically, the scaffolding files are correctly generated in foo/bar directories, but only the index method of the controller sets the variable @foo_bars, while other methods use @bars only. The index view also expects @bars, and so fails (since in this one case, @foo_bars is set, not @bars), and all views use bars_url instead of foo_bars_url, and have to be edited manually. Also, The route generated is still simply:


map.resources :bar

without any namespacing or nesting. According to other tickets, this problem also applies to:


ruby script/generate scaffold foo/bar

Finally, when all of the little bugs are corrected so that /foo/bars.xml returns a result, the XML is invalid:


<?xml version="1.0" encoding="UTF-8"?>
<foo/bars type="array">
  <foo/bar>
    <!-- ... -->
  </foo/bar>
</foo/bars>

Reported by Brandon Palmen · March 6th, 2009 @ 04:35 PM

State: stale
Milestone: none
Assigned to: nobody
Importance: Medium

Activity

  1. Brandon Palmen
    Brandon Palmen

    Could the invalid xml problem be solved by changing to <foo:bars> as such?

    
    # File vendor/rails/activesupport/lib/active_support/core_ext/array/conversions.rb, line 153
    
    
    options[:root] ||= all? { |e| e.is_a?(first.class) && first.class.to_s != "Hash" } ? first.class.to_s.split('::').collect{|c| c.underscore}.join(':').pluralize : "records"
    

    March 12th, 2009 @ 05:58 PM

  2. Brian Rose
    Brian Rose
    • Assigned user set to Ryan Bigg

    Bug replicated in 2.3.5 and 3.0. "rails g scaffold Foo::Bar" produces:

    class Foo::BarsController < ApplicationController
      # GET /foo_bars
      # GET /foo_bars.xml
      def index
        @foo_bars = Foo::Bar.all
    
        respond_to do |format|
          format.html # index.html.erb
          format.xml  { render :xml => @foo_bars }
        end
      end
    
      # GET /foo_bars/1
      # GET /foo_bars/1.xml
      def show
        @bar = Foo::Bar.find(params[:id])
    
        respond_to do |format|
          format.html # show.html.erb
          format.xml  { render :xml => @bar }
        end
      end
    
      ...
    end
    

    April 13th, 2010 @ 02:24 AM

  3. Brian Rose
    Brian Rose

    Same line in routes.rb when using 'rails g resource ...'.

    April 13th, 2010 @ 02:25 AM

  4. Brian Rose
    Brian Rose
    • Tag changed from 2.3, scaffold, scaffolding, sub-resource, xml to 2.3, 3.0, scaffold, scaffolding, sub-resource, xml

    Same line in routes.rb when using 'rails g resource ...'.

    April 13th, 2010 @ 02:26 AM

  5. Ryan Bigg
    Ryan Bigg
    • Assigned user cleared.

    I resolve myself of all responsibility of fixing things. I am only a ticket rustler. This does look like an enjoyable ticket though, perhaps I'll use it as an example for Railscamp.

    April 13th, 2010 @ 02:39 AM

  6. Ryan Bigg
    Ryan Bigg
    • Milestone cleared.

    I get valid XML for this:

    <?xml version=\"1.0\" encoding=\"UTF-8\"?>
    <foo-bars type=\"array\">
      <foo-bar>
        <created-at type=\"datetime\">2010-04-12T02:33:38Z</created-at>
        <id type=\"integer\">1</id>
        <updated-at type=\"datetime\">2010-04-12T02:33:38Z</updated-at>
      </foo-bar>
    </foo-bars>
    

    But I can confirm the routes and controllers issues.

    The Controller

    Perhaps for this, we should use a singularized version of table_name? I cannot even work out where file_name is coming from on this one.

    The Routes

    This is quite trivial. The code in the resource generator currently stands at:

      def add_resource_route
        return if options[:actions].present?
        route "resource#{:s unless options[:singleton]} :#{pluralize?(file_name)}"
      end
    

    Which quite obviously doesn't account for namespace routing at all, which I would say is a high priority "fix this before the Release Candidate or else it not be worth calling it a 'Release Candidate'" type of issue. Patches very much welcome on this.

    April 13th, 2010 @ 03:39 AM

  7. Francesc Esplugas
    Francesc Esplugas

    Here's an initial work for the scaffold templates.

    April 14th, 2010 @ 12:40 PM

  8. DHH
    DHH
    • Milestone cleared.

    May 4th, 2010 @ 05:31 PM

  9. Andrea Campi
    Andrea Campi
    • Importance changed from to High

    Works for me on 3.0.0

    October 8th, 2010 @ 04:09 PM

  10. Ryan Bigg
    Ryan Bigg
    • Importance changed from High to Medium

    October 9th, 2010 @ 12:07 AM

  11. Ryan Bigg
    Ryan Bigg
    • Tag cleared.

    Automatic cleanup of spam.

    October 19th, 2010 @ 08:22 AM

  12. Santiago Pastorino
    Santiago Pastorino
    • State changed from new to open

    This issue has been automatically marked as stale because it has not been commented on for at least three months.

    The resources of the Rails core team are limited, and so we are asking for your help. If you can still reproduce this error on the 3-0-stable branch or on master, please reply with all of the information you have about it and add "[state:open]" to your comment. This will reopen the ticket for review. Likewise, if you feel that this is a very important feature for Rails to include, please reply with your explanation so we can consider it.

    Thank you for all your contributions, and we hope you will understand this step to focus our efforts where they are most helpful.

    February 2nd, 2011 @ 04:29 PM

  13. Santiago Pastorino
    Santiago Pastorino
    • State changed from open to stale

    February 2nd, 2011 @ 04:29 PM