# Rails scaffolding issue

**URL:** <https://www.ruby-forum.com/t/rails-scaffolding-issue/194573>\
**Category:** Rails\
**Created:** [September 7, 2010, 11:42am UTC](https://www.ruby-forum.com/t/rails-scaffolding-issue/194573 "2010-09-07T11:42:07Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![JuKuen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@JuKuen](https://www.ruby-forum.com/u/JuKuen)\
**Post date:** [September 7, 2010, 11:42am UTC](https://www.ruby-forum.com/t/rails-scaffolding-issue/194573/1 "2010-09-07T11:42:07Z")

</div>

Greetings friends,

i`m experiencing an issue with scaffolding, which i`m unable to  
resolve for the moment.

system used:  
win7 x64: ruby -v 1.9.1, gem -v 1.3.7, rails -v 2.3.8. mysql 5.1.50,  
but downgraded to 5.0.37  
win xp x86: ruby -v 1.9.2, gem -v 1.3.7, rails - 3. mysql 5.1.50, but  
downgraded to 5.0.37  
slackware 13.1: ruby -v 1.9.2, gem -v 1.3.7, rails - 3. mysql 5.1.34

i have full mysql access, it is working, the issue persist in sqlite3  
aswell

When i try to scaffold from the existing table, im not getting the  
error while scaffolding, but after that the migration file is empty:

class CreatePosts \< ActiveRecord::Migration  
def self.up  
create\_table :posts do |t|

```
  t.timestamps
end

```

end

def self.down  
drop\_table :posts  
end  
end

When i fill it by hand,

class CreatePosts \< ActiveRecord::Migration  
def self.up  
create\_table :posts do |t|  
t.column :title, :string, :limit =\> 100, :null =\> false  
t.column :body, :text, :nill =\> false  
t.column :author, :string, :limit =\> 100, :null =\> false  
t.column :status, :string, :limit =\> 20, :null =\> false  
t.column :created\_at, :datetime  
t.column :updated\_at, :datetime  
end  
end

def self.down  
drop\_table :posts  
end  
end

and i try to test my app in the browser, i dont get the scaffolded  
fields, just one single button, when i click it, its renders the “new  
form” and there is only the create button alone, but when i click it,  
im getting the next error:

ActiveRecord::StatementInvalid in PostsController#create

SQLite3::ConstraintException: posts.title may not be NULL: INSERT INTO  
“posts” (“title”, “body”, “author”, “status”, “created\_at”,  
“updated\_at”) VALUES(NULL, NULL, NULL, NULL, ‘2010-09-07 08:53:20’,  
‘2010-09-07 08:53:20’)

RAILS\_ROOT: D:/sites/new

this is because sent information is empty, but there are no fields in  
the application.  
the problem is existing only if i use existing table in mysql, or  
trying to create migrations by hand.  
when i do:  
ruby script/generate scaffold Post blahblah:sting  
blahblah:text…, it is working fine  
with sqlite3.

Any help will be helpful

Thanks in Advance

---

<div class="post-metadata">

**Author:** ![JuKuen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@JuKuen](https://www.ruby-forum.com/u/JuKuen)\
**Post date:** [September 7, 2010, 12:47pm UTC](https://www.ruby-forum.com/t/rails-scaffolding-issue/194573/2 "2010-09-07T12:47:42Z")

</div>

On Sep 7, 10:41 am, JuKuen [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> this is because sent information is empty, but there are no fields in  
> the application.  
> the problem is existing only if i use existing table in mysql, or  
> trying to create migrations by hand.  
> when i do:  
> ruby script/generate scaffold Post blahblah:sting  
> blahblah:text…, it is working fine  
> with sqlite3.

That’s how scaffolding is (i think the change happened back in rails  
2). If you want the old dynamic scaffolding stuff you could look at  
something like active scaffold, or the old code was extracted into a  
plugin (don’t know if it’s still maintained):

> **[GitHub - rails/scaffolding: NOTICE: official repository moved to...](https://github.com/rails/scaffolding)**
>
> NOTICE: official repository moved to https://github.com/KeysetTS/scaffolding - GitHub - rails/scaffolding: NOTICE: official repository moved to https://github.com/KeysetTS/scaffolding

Fred

---

<div class="post-metadata">

**Author:** ![JuKuen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@JuKuen](https://www.ruby-forum.com/u/JuKuen)\
**Post date:** [September 7, 2010, 11:46am UTC](https://www.ruby-forum.com/t/rails-scaffolding-issue/194573/3 "2010-09-07T11:46:49Z")

</div>

edit:  
db/model names are plural/singular

---

<div class="post-metadata">

**Author:** ![JuKuen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@JuKuen](https://www.ruby-forum.com/u/JuKuen)\
**Post date:** [September 7, 2010, 2:43pm UTC](https://www.ruby-forum.com/t/rails-scaffolding-issue/194573/4 "2010-09-07T14:43:38Z")

</div>

If i understand it right, in new scaffold need to be specified each  
column from the existing db?

In my case:  
ruby script/generate scaffold Post title:string body:text  
author:string status:string created\_at:datetime updated\_at:datetime

And it will migrate the outside rails made db and will be working as  
is needed to be?  
Tested it and its working this way. Asking because dont want to learn  
it in wrong way.  
Used some outdated information… ☹

Thanks

---

<div class="post-metadata">

**Author:** ![JuKuen](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/7ba0ec/32.png) [@JuKuen](https://www.ruby-forum.com/u/JuKuen)\
**Post date:** [September 7, 2010, 4:40pm UTC](https://www.ruby-forum.com/t/rails-scaffolding-issue/194573/5 "2010-09-07T16:40:10Z")

</div>

whan you scafolded you didnt spefified the field of the database , the  
scafold creates empty views in that case , i think you didnt pass the  
fields  
because the scaffold fills the migration with them if you do, since i  
see  
the migration is empty that mians you did this

script/generate scaffold post  
and it should have been

script/generate scaffold post title:string body:text and so on
