<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/css" href="/stylesheets/rss.css"?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/">
  <channel>
    <title>ronin: Rails Scaffold, ActiveRecord, and table names</title>
    <link>http://blogs.divisibleprime.com/ronin/articles/2007/05/21/rails-scaffold-activerecord-and-table-names</link>
    <language>en-us</language>
    <ttl>40</ttl>
    <description>Stuff</description>
    <item>
      <title>Rails Scaffold, ActiveRecord, and table names</title>
      <description>&lt;p&gt;Looks like the Rails scaffolding doesn&amp;#8217;t like it when your model uses a different table name from the default mapping it expects(like when accessing a legacy database model).  &lt;/p&gt;

&lt;p&gt;So if you have a model like so:   &lt;/p&gt;

&lt;pre&gt;&lt;code&gt;class Thing &amp;lt; ActiveRecord::Base
    set_table_name "some_thing"
end
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Then ActiveRecord will be expecting a table called &amp;#8220;some_thing&amp;#8221;, however the scaffolding generator is expecting the default, which is going to be &amp;#8220;things&amp;#8221;(or something like that since I can&amp;#8217;t be bothered actually generating a model called Thing).&lt;/p&gt;

&lt;p&gt;When running your generator you&amp;#8217;re going to end up with an error like:&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;error  Before updating scaffolding from new DB schema, try creating a table for your model (Thing)
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;Annoying as this is, you can work around it by temporarily creating the table required by the generator.  Then go ahead and drop it after the generator works.&lt;/p&gt;

&lt;pre&gt;&lt;code&gt;create table things ();
&lt;/code&gt;&lt;/pre&gt;

&lt;p&gt;I&amp;#8217;m not sure what longer term effects this causes, and if there is a better way then let me know.  &lt;/p&gt;</description>
      <pubDate>Mon, 21 May 2007 20:36:00 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:c938c10a-7670-48fd-9f76-3eb6b9cac682</guid>
      <author>Kerry</author>
      <link>http://blogs.divisibleprime.com/ronin/articles/2007/05/21/rails-scaffold-activerecord-and-table-names</link>
      <category>Rails</category>
      <category>Tech</category>
      <category>Ruby</category>
      <category>ruby</category>
      <category>rails</category>
      <category>activerecord</category>
      <trackback:ping>http://blogs.divisibleprime.com/ronin/articles/trackback/870</trackback:ping>
    </item>
    <item>
      <title>"Rails Scaffold, ActiveRecord, and table names" by Gollo</title>
      <description>&lt;p&gt;In the meantime you could try &lt;a href="http://activescaffold.com/" rel="nofollow"&gt;http://activescaffold.com/&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Fri, 25 May 2007 14:18:20 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:0590bfc6-a111-4f85-aec4-e4969f8921e9</guid>
      <link>http://blogs.divisibleprime.com/ronin/articles/2007/05/21/rails-scaffold-activerecord-and-table-names#comment-15</link>
    </item>
    <item>
      <title>"Rails Scaffold, ActiveRecord, and table names" by Gollo</title>
      <description>&lt;p&gt;In the meantime you could try &lt;a href="http://activescaffold.com/" rel="nofollow"&gt;http://activescaffold.com/&lt;/a&gt;&lt;/p&gt;</description>
      <pubDate>Fri, 25 May 2007 14:18:17 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:143cb599-d76c-4430-8502-f8ab9e98d99f</guid>
      <link>http://blogs.divisibleprime.com/ronin/articles/2007/05/21/rails-scaffold-activerecord-and-table-names#comment-10</link>
    </item>
    <item>
      <title>"Rails Scaffold, ActiveRecord, and table names" by Kerry</title>
      <description>&lt;p&gt;Cool&lt;/p&gt;</description>
      <pubDate>Thu, 24 May 2007 18:48:07 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:fd6179bf-4bf9-4891-be86-19f8541bf196</guid>
      <link>http://blogs.divisibleprime.com/ronin/articles/2007/05/21/rails-scaffold-activerecord-and-table-names#comment-7</link>
    </item>
    <item>
      <title>"Rails Scaffold, ActiveRecord, and table names" by rach</title>
      <description>&lt;p&gt;by the way, koz has said they&amp;#8217;ve fixed this in 2.0. They&amp;#8217;ve redone the scaffolding totally apparently :)&lt;/p&gt;</description>
      <pubDate>Thu, 24 May 2007 11:11:03 +0100</pubDate>
      <guid isPermaLink="false">urn:uuid:ee6ee619-8f82-4320-bacb-33d8dc6b5eb8</guid>
      <link>http://blogs.divisibleprime.com/ronin/articles/2007/05/21/rails-scaffold-activerecord-and-table-names#comment-17</link>
    </item>
  </channel>
</rss>
