Forum: Ruby on Rails Scaffolding for pre-existing database table in 2.0.1

4d3d60b9c6d58cea876b6b906cb8dd90?d=identicon&s=25 Sebastian (Guest)
on 2007-12-10 04:16
(Received via mailing list)
Hi,

first of all I will apologize in advance for my presumably noobish
question, but I'm only starting to learn Rails and am a little
confused with all the changes in 2.0.1. There are as good as no
tutorials out yet and the 2 or 3 screencasts I've seen deal with the
creation of both the app and the database.

Now my problem is that I already have a database with a fair amount of
records in it (contacts with columns id:integer, first_name:string,
last_name:string). In order to get a simple CRUD interface (that's all
I want for now), with the pre-2.0 version of Rails,  I could simply
"generate scaffold contacts" and the framework would provide me with
all the necessary files to get started with (controller, model and
views).

When I try the same command ("generate scaffold contacts") in 2.0.1 it
will almost do the same thing, but somehow it misses all the fields
from the database. The list-view solely contains a long listing of
"Show Edit Destroy" lines (no first or last name listed here). When I
click on Edit, the form just provides me with an update button. So no
fields for first- and last name here either.

Is it supposed to be this way now in 2.0.1? If so, what can I do to
bring back the old functionality?

Regards,

Sebastian
9a2a53db8e9b4476038c94a64b32833f?d=identicon&s=25 Ryan Bigg (Guest)
on 2007-12-10 04:43
(Received via mailing list)
New way is to specify the fields.

script/generate scaffold person first_name:string last_name:string



On Dec 10, 2007 1:46 PM, Sebastian <sebastian.vogelsang@gmail.com>
wrote:

> records in it (contacts with columns id:integer, first_name:string,
> click on Edit, the form just provides me with an update button. So no
> fields for first- and last name here either.
>
> Is it supposed to be this way now in 2.0.1? If so, what can I do to
> bring back the old functionality?
>
> Regards,
>
> Sebastian
> >
>


--
Ryan Bigg
http://www.frozenplague.net
4d3d60b9c6d58cea876b6b906cb8dd90?d=identicon&s=25 Sebastian (Guest)
on 2007-12-10 04:53
(Received via mailing list)
Hey Ryan,

thanks for the quick answer.

I tried that multiple times before via the generator function in the
RadRails IDE and it didn't work (nothing happened, no error message).
It simply didn't create any controllers/views/models.
Just now I tried it again via the windows console, et voilà, ROR
creates all the classes like it used to. So it seems that this
malfunction was due to a bug/2.0-incompatibility in RadRails. Hope,
they'll fix this soon!

Thanks again,

Sebastian
8f6f95c4bd64d5f10dfddfdcd03c19d6?d=identicon&s=25 Rick Denatale (rdenatale)
on 2007-12-10 16:47
(Received via mailing list)
On 12/9/07, Ryan Bigg <radarlistener@gmail.com> wrote:
> New way is to specify the fields.
>
> script/generate scaffold person first_name:string last_name:string

And if the table already exists you might want to add --skip-migration

  script/generate scaffold person first_name:string last_name:string
--skip-migration

--
Rick DeNatale

My blog on Ruby
http://talklikeaduck.denhaven2.com/
7e2d58ab96ac0097c88f1ec9e137cde3?d=identicon&s=25 felipekk@gmail.com (Guest)
on 2007-12-10 21:27
(Received via mailing list)
I did this yesterday. You _HAVE_ to specify --skip-migration in case
its an existing model, else it will stop the whole "generate scaffold"
task before it creates the controller.
6ef8cb7cd7cd58077f0b57e4fa49a969?d=identicon&s=25 Brian Hogan (Guest)
on 2007-12-11 07:22
(Received via mailing list)
Ok, been following this all day.

Scaffolding is really not great for production, but it is nice to have
it
build the forms for you. It saves me some typing at least, and I find
that's
what most people are after with the scaffolding.  With that in mind, I
took
some of the old scaffolding code and made it into a gem.  It's designed
to
work off of a pre-existing model.

sudo gem install scaffold_form_generator

Then just do

ruby script/generate scaffold_form User users

It will build these files

/app/views/users/new.html.erb
/app/views/users/edit.html.erb
/app/views/users/_form.html.erb

The form builder skips created_at, updated_at, lock_version, and
anything
with _id at the end.  It also makes boolean fields checkboxes instead of
true/false dropdowns.

Learn more at

http://scaffoldform.rubyforge.org

Now, it doesn't do "everything" completely RESTful yet but it's a really
good start. If you have suggestions, let me know. It's not going to ever
be
extended to handle relationships - I looked into it and it's not worth
trying - too hard to know what you are trying to relate, what you want
to
show in your dropdowns, etc.

-bph
Ca8fc96880b541422f2f56256716658e?d=identicon&s=25 Mr Mapes (mmapes)
on 2008-01-08 06:14
Ryan Bigg wrote:
> New way is to specify the fields.
>
> script/generate scaffold person first_name:string last_name:string
>

I'm considering Ruby on Rails, but I already have a big database schema,
and I'd rather not re-type firstname:string lastname:string, for the
dozens of fields in my dozens of tables. Is there some way for Ruby to
build the scaffold based on what it finds in the existing database?
Wasn't that the whole point in previous versions? This seems like a big
step backwards....
9a2a53db8e9b4476038c94a64b32833f?d=identicon&s=25 Ryan Bigg (ryan-bigg)
on 2008-01-08 06:20
(Received via mailing list)
The idea is that Rails doesn't know which of your fields you want to
include, or what kind they are.

It'll be easier for you to type them and design your own layout.
Ca8fc96880b541422f2f56256716658e?d=identicon&s=25 Mr Mapes (mmapes)
on 2008-01-08 06:21
... and one more comment/question... how can I prevent Ruby from
pluralizing my model. Say my table is called "game." If I try this new
scaffold with...

ruby script/generate scaffold game name:string

... what I get in my file structure is "games" (plural), but the table
in my existing database is "game" (singular). I then get SQL errors on
like "Table db.games doesn't exist."
9a2a53db8e9b4476038c94a64b32833f?d=identicon&s=25 Ryan Bigg (ryan-bigg)
on 2008-01-08 06:43
(Received via mailing list)
Not too sure on that, I was sure that scaffolding named everything
correctly.

On Jan 8, 2008 3:51 PM, Mr Mapes <rails-mailing-list@andreas-s.net>
wrote:

> --
> Posted via http://www.ruby-forum.com/.
>
> >
>


--
Ryan Bigg
http://www.frozenplague.net
Feel free to add me to MSN and/or GTalk as this email.
6ef8cb7cd7cd58077f0b57e4fa49a969?d=identicon&s=25 Brian Hogan (Guest)
on 2008-01-08 14:39
(Received via mailing list)
On Jan 7, 2008 11:21 PM, Mr Mapes <rails-mailing-list@andreas-s.net>
wrote:

>  --
> Posted via http://www.ruby-forum.com/.
>
>  You're not following conventions, which is explained by your use of the
legacy schema. Rails assumes that table names are plural and model names
are
singular.

What you actually need to do is run the scaffold as such:

   ruby script/generate scaffold game name:string

Then open up app/models/game.rb

Add the "set_table_name" method call to tell the model to use the
singular
table.

class Game < ActiveRecord::Base
   set_table_name "game"
end


If your primary key is not called "id" then you can specify that as
well. Be
warned though - Rails likes integers for its keys.

 class Game < ActiveRecord::Base
   set_table_name "game"
   set_primary_key "game_id"
end

Finally, Rails is not about scaffolding. That was a marketing trick to
get
people sucked in. Most people who do Rails professionally don't use
scaffolding at all, as it often generates a bunch of code you don't
need, or
is not complex enough to handle the basic tasks.
4e9b34b410463c486f8d1ca11f5ce892?d=identicon&s=25 Ron Phillips (paron)
on 2008-01-08 20:08
(Received via mailing list)
On Jan 8, 8:38 am, "Brian Hogan" <bpho...@gmail.com> wrote:

> Finally, Rails is not about scaffolding. That was a marketing trick to get
> people sucked in. Most people who do Rails professionally don't use
> scaffolding at all, as it often generates a bunch of code you don't need, or
> is not complex enough to handle the basic tasks.

I do (or did) use scaffolding. It's probably a unique situation: I
work for a government agency that has a large number of legacy
datatables which just need maintenance API's stuck onto them to do
CRUD on our intranet.

Some of these monsters have a bajillion fields, and I can erase code a
whole lot faster than I can type it. So, I used "scaffold Monster" all
the time.

I'm sure you're right about most people who do Rails professionally,
though. If I were making standalone websites, like most folks,
scaffolding might be a distraction. I'd do paper prototypes first,
then code as needed in that situation.

I really miss the "old school" scaffolding -- in fact, I may recreate
it and call it something else like scaffold_api or scaffold_crud or
something. Thanks for the scaffold_form_generator, by the way -- it
put back a lot of what I missed the most.

Ron
6ef8cb7cd7cd58077f0b57e4fa49a969?d=identicon&s=25 Brian Hogan (Guest)
on 2008-01-08 20:34
(Received via mailing list)
Ron:

Well, in that case, check out my gem.
http://scaffoldform.rubyforge.org

It uses the old-style model reflection to build just the form (new,
edit,
and _form.html.erb) It doesn't generate models or controllers... just
the
views for the form. I did this for exactly the reason you outlined..
generating a form can be handy.  I basically took the old code from
Rails
1.2.3 and made it work with 2.0, with a few minor exceptions:  anything
with
_id is not generated as a field,  created_at and updated_at fields are
skipped,  and anything that's a boolean gets a checkbox instead of a
dropdown.

Maybe that will help.
6ef8cb7cd7cd58077f0b57e4fa49a969?d=identicon&s=25 Brian Hogan (Guest)
on 2008-01-08 20:36
(Received via mailing list)
lol I missed the end of your reply :) Looks like you already are using
it.
Do you have any suggestions for additions to it?
0b161ccdc3c3f56bfc43f493ba8807aa?d=identicon&s=25 Tony Ennis (tony-ennis)
on 2009-03-27 15:49
Mr Mapes wrote:
> Ryan Bigg wrote:
>> New way is to specify the fields.
>>
>> script/generate scaffold person first_name:string last_name:string
>>
>
> I'm considering Ruby on Rails, but I already have a big database schema,
> and I'd rather not re-type firstname:string lastname:string, for the
> dozens of fields in my dozens of tables. Is there some way for Ruby to
> build the scaffold based on what it finds in the existing database?
> Wasn't that the whole point in previous versions? This seems like a big
> step backwards....

I'm a little late to the party here.

Try this from script/console

>> TableClass.columns.each { |c| puts c.inspect }; nil

You'll see a list of all the columns in the table, along with the data
types and names and so forth.  It should be a pleasurable afternoon to
write a script that consumes this and generates a "script/generate
scaffold" command.
B89e71f3ec3ceb82776827014870da66?d=identicon&s=25 Humberto P. (humberto_p)
on 2012-12-06 19:09
Mr Mapes wrote in post #613756:
> Ryan Bigg wrote:
>> New way is to specify the fields.
>>
>> script/generate scaffold person first_name:string last_name:string
>>
>
> I'm considering Ruby on Rails, but I already have a big database schema,
> and I'd rather not re-type firstname:string lastname:string, for the
> dozens of fields in my dozens of tables. Is there some way for Ruby to
> build the scaffold based on what it finds in the existing database?
> Wasn't that the whole point in previous versions? This seems like a big
> step backwards....

Probably to late for Ryan Bigg problem, but
there is a cool gem called schema_to_scaffold to generate a scaffold
script.
it outputs: rails g scaffold users fname:string lname:string bdate:date
email:string encrypted_password:string
from your schema.rb our your renamed schema.rb. Check [here][1]

  [1]: https://rubygems.org/gems/schema_to_scaffold
5a2e7ad0ac14916775fb47c651cdbb7a?d=identicon&s=25 Al Rushing (alrushing)
on 2014-08-29 19:40
Sebastian wrote in post #599469:
> Hi,
>
> first of all I will apologize in advance for my presumably noobish
> question, but I'm only starting to learn Rails and am a little
> confused with all the changes in 2.0.1. There are as good as no
> tutorials out yet and the 2 or 3 screencasts I've seen deal with the
> creation of both the app and the database.
>
> Now my problem is that I already have a database with a fair amount of
> records in it (contacts with columns id:integer, first_name:string,
> last_name:string). In order to get a simple CRUD interface (that's all
> I want for now), with the pre-2.0 version of Rails,  I could simply
> "generate scaffold contacts" and the framework would provide me with
> all the necessary files to get started with (controller, model and
> views).
>
> When I try the same command ("generate scaffold contacts") in 2.0.1 it
> will almost do the same thing, but somehow it misses all the fields
> from the database. The list-view solely contains a long listing of
> "Show Edit Destroy" lines (no first or last name listed here). When I
> click on Edit, the form just provides me with an update button. So no
> fields for first- and last name here either.
>
> Is it supposed to be this way now in 2.0.1? If so, what can I do to
> bring back the old functionality?
>
> Regards,
>
> Sebastian


       Just another quick solution.   You can generate the Ruby
scaffolding commands using SQL out of the database.   Just access
sys.columns or whatever your particular database provides
(INFORMATION_SCHEMA or something).   For each column, generate that line
that Ruby wants for a column / table entry.   Then you can select as you
want for the Ruby app deleting unwanted column / table lines.

       Does anyone have a definitive Ruby generation command for Nifty
using Ruby 4, for an existing database?  I could generate the entire
thing via SQL, which I would be happy to provide.
5a2e7ad0ac14916775fb47c651cdbb7a?d=identicon&s=25 Al Rushing (alrushing)
on 2014-08-29 19:41
Just another quick solution.   You can generate the Ruby
scaffolding commands using SQL out of the database.   Just access
sys.columns or whatever your particular database provides
(INFORMATION_SCHEMA or something).   For each column, generate that line
that Ruby wants for a column / table entry.   Then you can select as you
want for the Ruby app deleting unwanted column / table lines.

       Does anyone have a definitive Ruby generation command for Nifty
using Ruby 4, for an existing database?  I could generate the entire
thing via SQL, which I would be happy to provide.
740e41374dfaafa94c3e648935049e44?d=identicon&s=25 Richard Lenawasae (richardlenawasae)
on 2014-10-03 16:04
Email Address:richardlenawasae@gmail.com
Hi,

I'm developing a heavy project using Ruby on Rails, and I already have a
big database schema in my sublime text,but my database has a dozen of
fields of tables which are sometimes very tiresome when scaffolding such
as £rails g scaffold profile firstname:string lastname:string,
....Please show me any other alternative on how to handle such
scenario..

I ll be glad to know.

Thanks...
Dfc7587fd73f2efa19d6f1f9611b70ba?d=identicon&s=25 Jason Fb (jasonfb)
on 2014-10-03 16:21
(Received via mailing list)
Although old, ActiveScaffold is still an excellent, efficient,
unobtrusive, scalable, and highly effective solution to build out lots
of quick list views (complete with searching, sorting, and pagination)
and CRUD actions.

Check out: http://activescaffold.com

The front-end isn't very aesthetic, but with a little CSS love that can
be easily fixed.  Personally I use ActiveScaffold for back-end
(admin-view) pages, and then write my own controllers for front-end
(user-facing) functionality.

Here's a list of other alternatives to ActveScaffold for you to consider
as well:

https://www.ruby-toolbox.com/search?utf8=✓&q=scaffold




On Oct 3, 2014, at 10:04 AM, Richard Lenawasae <lists@ruby-forum.com>
wrote:

> I ll be glad to know.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk....
> For more options, visit https://groups.google.com/d/optout.
>

----

Jason Fleetwood-Boldt
tech@datatravels.com
http://www.jasonfleetwoodboldt.com/writing

All material © Jason Fleetwood-Boldt 2014. Public conversations may be
turned into blog posts (original poster information will be made
anonymous). Email jason@datatravels.com with questions/concerns about
this.
740e41374dfaafa94c3e648935049e44?d=identicon&s=25 Richard Lenawasae (richardlenawasae)
on 2014-10-03 17:13
Email Address:richardlenawasae@gmail.com>>>Jason Fleetwood-Boldt

@Jasonfb, i guess i did alot of research on ruby on rails as far
scaffolding is concern, but you find when it comes on real world
boilerplate applications..it's kind of a nightmare when we try oldschool
method 'scalfolding' because it may take you actually the whole day
scaffolding even one table that contains over 100 colum fields..may be
tell me some procedures on how to use activescaffold..!!
Dfc7587fd73f2efa19d6f1f9611b70ba?d=identicon&s=25 Jason Fb (jasonfb)
on 2014-10-03 17:33
(Received via mailing list)
I generally do not use the rails built-in scaffolding generators. They
are from the early days of rails and while they may have some
usefulness, they do not save me time in the long run.

One table that contains over 100 column fields doesn't sound like a good
database design -- maybe you should step back and think of a way to
create a more management data model.

ActiveScaffold lets you write very little code and get a very usable
out-of-the-box list & CRUD views for admin-facing pages. Like I said, I
would not use it for front-facing part of the site.

I have found it to be well documented, although trying to do certain
more complex things can get tricky.

https://github.com/activescaffold/active_scaffold

http://activescaffold.com



On Oct 3, 2014, at 11:13 AM, Richard Lenawasae <lists@ruby-forum.com>
wrote:

> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email
to rubyonrails-talk+unsubscribe@googlegroups.com.
> To post to this group, send email to rubyonrails-talk@googlegroups.com.
> To view this discussion on the web visit
https://groups.google.com/d/msgid/rubyonrails-talk....
> For more options, visit https://groups.google.com/d/optout.
>

----

Jason Fleetwood-Boldt
tech@datatravels.com
http://www.jasonfleetwoodboldt.com/writing

All material  Jason Fleetwood-Boldt 2014. Public conversations may be
turned into blog posts (original poster information will be made
anonymous). Email jason@datatravels.com with questions/concerns about
this.
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.