scaffold not listing my colums from database

3 views
Skip to first unread message

Kyle Gwinnup

unread,
Nov 4, 2007, 4:06:53 PM11/4/07
to rubyonra...@googlegroups.com
I am using Leopard and just got rails installed. However, when i do a
sample application to test everything, my scaffold project does not show
any of the information from the database. below is my migrate file. So
basically after doing rake db:migrate and creating the scaffold, nothing
shows up when i test this. the page loads, but all it allows me to do
is create new but will not show me any controls to enter information.

class CreateProducts < ActiveRecord::Migration
def self.up
create_table :products do |t|
t.column :title, :string
t.column :description, :text
t.column :image_url, :string
end
end

def self.down
drop_table :products
end
end
--
Posted via http://www.ruby-forum.com/.

Ian Seabock

unread,
Nov 4, 2007, 4:32:08 PM11/4/07
to rubyonra...@googlegroups.com

Hey,

I don't know if you are having the same issue as me but this might help.
I am on a Win machine and installed RoR with Instant Rails. Now I do all
of the development in a rails apps directory but in order for my changes
to be seen I have to copy everything over to the www directory.

I have been wanting to post about this for a while but just haven't
gotten around to it and I have just gotten use to it. Hope this helps.
Good luck.

s.ross

unread,
Nov 4, 2007, 4:35:04 PM11/4/07
to rubyonra...@googlegroups.com

Well, you do have to write a *little* code :)

<% form_for(@product) do |f| %>
<p><%= f.text_field :title %></p>
<p><%= f.text_area :description %></p>
<p><%= f.text_field :image_url %></p>
<% end -%>

Or something like that. Only you know what fields you want to expose
to the user and which controls you want to use for input.

Kyle Gwinnup

unread,
Nov 4, 2007, 5:00:26 PM11/4/07
to rubyonra...@googlegroups.com

So does scaffold not do this for you? I am following a book and it says
nothing about this yet. It is showing me how scaffold is used.

s.ross

unread,
Nov 4, 2007, 5:23:55 PM11/4/07
to rubyonra...@googlegroups.com

It used to, but no longer. It also used to fill in the fields for the
list (now index) method and show method. Not sure why the change.

You obviously have a nice new version of Rails and a slightly out of
date book. That's what's great about this list. You catch up in a hurry.

William Pratt

unread,
Nov 4, 2007, 5:26:37 PM11/4/07
to rubyonra...@googlegroups.com
You don't need to write any of that code as long as you add the
scaffold directive to your controller or use the scaffold generator.
If you generated a blank controller, make sure you add
scaffold :somemodel inside the controller class. This is not needed if
you used the scaffold generator.

-Bill

On Nov 4, 2007, at 2:00 PM, Kyle Gwinnup wrote:

Kyle Gwinnup

unread,
Nov 4, 2007, 5:27:55 PM11/4/07
to rubyonra...@googlegroups.com
Steve Ross wrote:
> On Nov 4, 2007, at 2:00 PM, Kyle Gwinnup wrote:
>
>>> Well, you do have to write a *little* code :)
>> So does scaffold not do this for you? I am following a book and it
>> says
>> nothing about this yet. It is showing me how scaffold is used.
>> --
>
> It used to, but no longer. It also used to fill in the fields for the
> list (now index) method and show method. Not sure why the change.
>
> You obviously have a nice new version of Rails and a slightly out of
> date book. That's what's great about this list. You catch up in a hurry.

interesting. well, thats cool. i didnt plan on using scaffold anyways,
just new to rails and thought i would try to do all the examples in the
book. So is scaffolding even around anymore?

William Pratt

unread,
Nov 4, 2007, 5:32:39 PM11/4/07
to rubyonra...@googlegroups.com
It definitely still does (thats what it's for?) and I just tested it.
Here is the documentation for scaffold:

http://api.rubyonrails.org/classes/ActionController/Scaffolding/ClassMethods.html#M000165

-Bill

Kyle Gwinnup

unread,
Nov 4, 2007, 5:33:20 PM11/4/07
to rubyonra...@googlegroups.com
William Pratt wrote:
> You don't need to write any of that code as long as you add the
> scaffold directive to your controller or use the scaffold generator.
> If you generated a blank controller, make sure you add
> scaffold :somemodel inside the controller class. This is not needed if
> you used the scaffold generator.
>
> -Bill

Bill,

thats seems to be what i am doing. in my controller i have one line it
it:

scaffold:product

but when i try and view the page it doesnt show any of the columns from
my table. I am going through the book agile web development with rails
(second edition). is that book out of date when it comes to
scaffolding?

s.ross

unread,
Nov 4, 2007, 5:34:32 PM11/4/07
to rubyonra...@googlegroups.com
There has been talk about removing dynamic scaffolding, and I'm not
sure what the status is. The generator is still around, but as you
observed (and I did a couple of days ago), the behavior has changed.
Side note: For stuff that's not public-facing, it's surprising how
long scaffolded code can last :) I have an app that's been in
production since before Rails 1.0 and there's still some scaffold
code in it. Happy client because he got a great deal on the code I
didn't write.

Here's a search that may give you some insight into what Rails Core
is saying about scaffolding:

http://www.nabble.com/forum/Search.jtp?
forum=13832&local=y&query=scaffold

s.ross

unread,
Nov 4, 2007, 5:39:28 PM11/4/07
to rubyonra...@googlegroups.com
On Nov 4, 2007, at 2:33 PM, Kyle Gwinnup wrote:

>
> William Pratt wrote:
>> You don't need to write any of that code as long as you add the
>> scaffold directive to your controller or use the scaffold generator.
>> If you generated a blank controller, make sure you add
>> scaffold :somemodel inside the controller class. This is not
>> needed if
>> you used the scaffold generator.
>>
>> -Bill

He's running on a pretty new version of Rails, and that provides,
essentially, scaffold_resource from the generator. Please see http://
dev.rubyonrails.org/changeset/7429 for the changeset that recommends
using the scaffold generator.

William Pratt

unread,
Nov 4, 2007, 5:39:37 PM11/4/07
to rubyonra...@googlegroups.com
No, it is current for rails 1.2 and as long as you are running the 1.2
version, scaffold will create all of the fields except for
relationships. It will do this for list, create, edit, etc. What
happens when you call that controller's new action:

http://localhost:3000/products/new

I assume your controller is ProductsController and looks like this:

class ProductsController < ApplicationController
scafflod :product
end

I just tested this on rails 1.2.5 / ruby 1.8.6 and it works as it
always has. If it's still not working, is there anything in your logs?
Can you create a product from the console?

-Bill

William Pratt

unread,
Nov 4, 2007, 5:43:19 PM11/4/07
to rubyonra...@googlegroups.com
Ok, maybe this is a rails 2.0 thing, but I am running 1.2.6 (I said
1.2.5 earlier), and it still works fine for me? If you are running
rails 2.0 edge, you should downgrade to 1.2.6 if you want to follow
along with that book which is currently the latest book.

-Bill

On Nov 4, 2007, at 2:39 PM, s.ross wrote:

> dev.rubyonrails.org/changeset/7429

Reply all
Reply to author
Forward
0 new messages