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.
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.org for more details.
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 Development 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 (www.manning.com/black) as well, as it focuses a bit more on the
Ruby language while still giving you the fundamentals of solid Rails
programming.
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)
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.
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
and "new" or "edit" gave me the "file / upload" option
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.
All the Best!
Sergey.
Ajax_scaffold junior developer