This project is archived and is in readonly mode.

#2156 ✓stale
Brandon Palmen

Problems with scaffolding of subclasses

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

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>

Comments and changes to this ticket

  • Brandon Palmen

    Brandon Palmen March 12th, 2009 @ 05:58 PM

    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"
    
  • Brian Rose

    Brian Rose April 13th, 2010 @ 02:24 AM

    • 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
    
  • Brian Rose

    Brian Rose April 13th, 2010 @ 02:25 AM

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

  • Brian Rose

    Brian Rose April 13th, 2010 @ 02:26 AM

    • 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 ...'.

  • Ryan Bigg

    Ryan Bigg April 13th, 2010 @ 02:39 AM

    • 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.

  • Ryan Bigg

    Ryan Bigg April 13th, 2010 @ 03:39 AM

    • 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.

  • Francesc Esplugas

    Francesc Esplugas April 14th, 2010 @ 12:40 PM

    Here's an initial work for the scaffold templates.

  • DHH

    DHH May 4th, 2010 @ 05:31 PM

    • Milestone cleared.
  • Andrea Campi

    Andrea Campi October 8th, 2010 @ 04:09 PM

    • Importance changed from “” to “High”

    Works for me on 3.0.0

  • Ryan Bigg

    Ryan Bigg October 9th, 2010 @ 12:07 AM

    • Importance changed from “High” to “Medium”
  • Ryan Bigg

    Ryan Bigg October 19th, 2010 @ 08:22 AM

    • Tag cleared.

    Automatic cleanup of spam.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:29 PM

    • 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.

  • Santiago Pastorino

    Santiago Pastorino February 2nd, 2011 @ 04:29 PM

    • State changed from “open” to “stale”

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile »

<h2 style="font-size: 14px">Tickets have moved to Github</h2>

The new ticket tracker is available at <a href="https://github.com/rails/rails/issues">https://github.com/rails/rails/issues</a>

People watching this ticket

Attachments

Pages