List Info

Thread: Re: Scaffolding Without Migration? - Porting CakePHP App To




Re: Scaffolding Without Migration? - Porting CakePHP App To
user name
2008-02-24 04:00:20
Much appreciated Mark.

I guess the short answer is that, that's not the way Rails 2.0 works.

I was wondering whether the step: script/generate scaffold Sample name:string description:string
could (somehow) pull the fields from a DB schema/migration (imported from the database), and the answer is no.

Thank you, much appreciated again.
--
Kevin Lloyd
3HN Designs
http://www.3HNDesigns.com/
(214) 473-4207

On Sun, Feb 24, 2008 at 3:51 AM, Mark Bush < rails-mailing-listandreas-s.net">rails-mailing-listandreas-s.net> wrote:

Baz wrote:
&gt;    1. design a database and point to it.
>    2. Use the generator to create my models then add my associations.
>    3. Use the generator to generate scaffolds (not sure this is the
> right
&gt;    term) of the controllers and views.

The equivalent in Rails 2 is:

1. design your database (on paper)
2. use the generator to create migrations, models, controllers, views
3. apply the migrations to the database
4. add your associations to your models

So, if you need a model Sample with database table samples which has
columns name & description, run:

script/generate scaffold Sample name:string description:string
rake db:migrate

Now you have:
db/migrate/001_create_samples.rb
which is your migration which you have applied to the database (the
&quot;rake&quot; command will apply all outstanding migrations so you can scaffold
all your models first, then run the migrations in one go).

You also have:
app/models/sample.rb
app/controllers/samples_controller.rb
app/views/samples/edit.html.erb
app/views/samples/index.html.erb
app/views/samples/new.html.erb
app/views/samples/show.html.erb

The controller has actions for listing, adding, editing, and creating
Sample objects.  The views will display things for you.  If you didn't
specify any fields when you ran the scaffold, then the views will have
no references to fields. The views are *very* basic.  You will want to
edit them except in very simple (rare) cases.  Note also that the
generated views will not handle any special fields.  If a field is a
foreign key to another model, you will just get a text field to input
the ID of the row for the other model.  You&#39;ll have to handle extracting
the data and creating, say, a select element yourself.


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
To post to this group, send email to rubyonrails-talkgooglegroups.com
To unsubscribe from this group, send email to rubyonrails-talk-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---

[1]

about | contact  Other archives ( Real Estate discussion Medical topics )