Forum: Ruby on Rails Documentation for scaffold / views

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
6dfd01c549aa33a158730c7d9f7064cc?d=identicon&s=25 Da Plutes (plutes)
on 2006-01-19 01:29
Apparently a scaffold creates at least one instance variable for views
to use, and if I override the scaffold then I must also explicitly
create that instance variable for the view. I'd like to know exactly
what work is performed by the scaffold so that I can know this when
over-riding the view. (OR, is it that the controller makes these
variables available by default?..)


EXAMPLE:   (drawn from Recipes tutorial)

Let's start with this:

class CategoryController < ApplicationController
	scaffold :category
end


Now app/views/category/show.rhtml can access @category. However as soon
as I over-ride the show, like so...

class CategoryController < ApplicationController
	scaffold :category
	def show
	end
end

..@category is no longer available to the show view because I neglected
to do so explicitly. I can fix that like so:

class CategoryController < ApplicationController
	scaffold :category

	def show
		@category = Category.find(params[:id])
	end
end


Which docs or code would tell me more about this and other such
variables and methods that are made available by either the controller
or scaffold and that I must take care to recreate if I over-ride the
category controller?

THanks
58c44a4a506d878f9a112f1d7b7cb87e?d=identicon&s=25 Jeremy Evans (Guest)
on 2006-01-19 02:49
(Received via mailing list)
On 1/18/06, dr plutes <pluto1@gmail.com> wrote:
> Which docs or code would tell me more about this and other such
> variables and methods that are made available by either the controller
> or scaffold and that I must take care to recreate if I over-ride the
> category controller?

Assuming you are running Edge Rails, the code is in:

RAILS_ROOT/vendor/rails/actionpack/lib/action_controller/scaffolding.rb
C8a634a01a2c4508360874bff7fb1a7f?d=identicon&s=25 Kevin Olbrich (olbrich)
on 2006-01-19 03:35
It would also be a good idea to simply run the scaffold generator.  That
will actually spell out all the code for you in a controller file.  You
can then replace stuff as needed, but you can also see the code.

ruby script/generate scaffold model

_Kevin
6dfd01c549aa33a158730c7d9f7064cc?d=identicon&s=25 da plutes (Guest)
on 2006-01-19 07:49
Kevin Olbrich wrote:
> It would also be a good idea to simply run the scaffold generator.  That
> will actually spell out all the code for you in a controller file.  You
> can then replace stuff as needed, but you can also see the code.
>
> ruby script/generate scaffold model
>
> _Kevin

YeaH, I've started to do that with my new rails apps.  I have an earlier
one that I still use and didn't want to wipe out my work done by
generating the scaffold.  I'm not quite sure how well the --skip option
avoids overwrites either, but yeah henceforth that's the way I'm going
to go every time.  Is there any reason NOT to just generate the full
scaffold every time?
This topic is locked and can not be replied to.