sorry i forgot you use scaffold , here is the thing ill make a guide for
this , from the migration step by step to the view
create a table like this
create_table :sugestions do |t|
t.string first_name
t.string last_name
t.string email
t.string business_name
t.string business_address
t.string city_name
t.string type
end
no more tables are needed
create a model
Sugestion , (singular) as normal it should inherit from active record
base
like this
class Sugestion < ActiveRecord::Base
attr_accessible : first_name,last_name, email, business_name,
business_address, city_name
then create the tu other model that inherit from Sugestion, note that is
they is a capital letter in the model name rails will put an underscore
like
this city_sugestions_controller
class CitySugestion < ActiveRecord::Base
attr_accessible : first_name,last_name, email, city_name
and another
class bussinessSugestion < ActiveRecord::Base
attr_accessible : first_name,last_name, email,business_name,
business_address
note i think type should not be available with mass assignment.
then create the controllers for the 2 sugestions classes
city_sugestions_controller
and
bussiness_sugestions_controller
from here one this controller will never notice you have only one table
they
will behave as if you had 2 different tables in the db
in you views just refer to @bussinesssugestions and it will be scoped
thanks
to the type field that active record will automaticly use then you save
an
object of either class. Dont try to access the type field using
@citysuggestion.type or @suggestion.type as type is a ruby method and
will
be called instead of
the table field, use @sugestion[:type] , the other fields can be called
as
normal.
If you want to handle the sugestion class directly you can create a
sugestions_controller, it its corresponding viwes for it and have a
named
scope that filter each type.
Dont be afraid to keep asking if you are still confuse and keep in mind
that
in most case, people are not specting that you would use scaffolds every
time since scaffold are more like a learning tool that an actual way of
doing things.
if you want to use scaffold anyway you can create the scaffold and skip
creating the migrations with
script/generate scaffold --skip-migrations
On Thu, Sep 9, 2010 at 9:52 AM, Christian F. <