Scaffolding Question

Hello,
I am creating a management system and used scaffolding to create
the setup for the admin portion. I have it linked to an Account
database, and the new account form is filled with the fields from the
database. Some of the fields in the database are not meant for the
user to fill in but the system itself when the record is processed.
What is the best way of going about making those fields invisible to
the form? Basically, I need the system to input data to those records
as needed.

Thanks!

Sincerely,
Michael Novak

Scaffolding in Rails 1.1.6 is very rudimentary. For beginners it is
better
to stay away from it. Rails 1.2 RC1 scaffolding is much better and you
can
use it as a good start for your project.

In 1.1.6, the view uses reflection to iterate through all the fields in
the
database, so you must change it to display only the fields that you want
to
be visible to the user. You have to use tags for each field that will
generate the html elements. Look at the docs at
http://api.rubyonrails.orgfor more details.

Mike wrote:

Hello,
I am creating a management system and used scaffolding to create
the setup for the admin portion.

Scaffolding is really just example code, not intended for production.
Like the word scaffolding implies, it’s meant to be temporary while you
get your application up and running.

Get a Rails book like Agile Web D. with Rails (pragprog.com) -
the 2nd edition is supposed to ship any day now. It’s a great book for
someone new to Rails. I also really liked Ruby for Rails by David A.
Black (Ruby for Rails) as well, as it focuses a bit more on the
Ruby language while still giving you the fundamentals of solid Rails
programming.

Jeff

You have two options:

  1. use hidden fields
  2. remove the field from the view completely and fill them in in your
    controller create action. For example:

JUST SAVE DATA FROM FORM:

@person = Person.new(params[:person])
if @person.save

ADD SOME OTHER STUFF:

@person = Person.new(params[:person])
@person.agreed_to_disclaimer_at = Time.now
@person.languages = params[:person][:l1] + params[:person][:l2]
if @person.save

As others have said, scaffolding gives you a starting point and you
will very quickly out grow it.

I would suggest building your own forms and methods to handle the
fields, but stay away from hidden fields (they are too easily hacked).
You will learn more about how Rails work and become more secure and
productive in the process.

Also, if the fields are super sensitive, check out attr_protected
(ActiveRecord::Base)

On 12/13/06, Mike [email protected] wrote:

  I am creating a management system and used scaffolding to create

the setup for the admin portion. I have it linked to an Account
database, and the new account form is filled with the fields from the
database. Some of the fields in the database are not meant for the
user to fill in but the system itself when the record is processed.
What is the best way of going about making those fields invisible to
the form? Basically, I need the system to input data to those records
as needed.

The Scaffolding Extensions plugin [1] can do that.

Jeremy

[1]
http://wiki.rubyonrails.com/rails/pages/Scaffolding+Extensions+Plugin

I recently started playing with ajax_scaffold and it’s pretty
impressive. One thing I noticed, was that any field containing “_id”)
was not shown in the scaffold GUI.

For example, I appled the scaffold to a table which had the following
fields:
“id”, “person_id”, “attribute”, “value”

In the scaffold GUI, all that was shown was “attribute” and “value”.

I agree that building your own CRUD interface is best but… if you’re
even remotely as lazy as I am, you could just suffix a field with
“_id” and it might be hidden.

Check it out @ http://www.ajaxscaffold.com… setup was exteremely easy:

gem install ajax_scaffold_generator
ruby script/generate ajax_scaffold Attrubute ##for table named
attributes

–then open http://:/attributes :slight_smile:

Good luck

It’s a nice GUI. I think it hides the id fields because these are
basically glue to hold the tables together. Ajaxscaffold still gives
you way to add associated information to models (I think).

Ya… right now, I have an images table with blob images. --would be
nice if scaffolding interpreted the content/type and rendered
gifs/jpegs/pngs automatically :slight_smile:

and “new” or “edit” gave me the “file / upload” option :slight_smile:

I cant wait!

New ajax_scaffold version 4.0 does support _id, and even realizes if
there has_many, belongs_to, habtm
associations so you can show them by default or redefine representation
for each and any controllers and
fields in that controller, as well as way more points of configuration.

This version is a major redesign of the plugin. You will see it yourself
soon.

Keep tuned for ASp. :slight_smile:

All the Best!
Sergey.
Ajax_scaffold junior developer :slight_smile: