Newbie question: creating views to submit values


#1

Apologies for such a basic question. I’ve wracked my brain on this a
couple days so if anyone takes pity, please help me out.

I’ve been looking at STI (Single Table Inheritance) at the Rails Wiki
and decided to try it out. I got it working in the model and
controllers but can’t figure out how to make a proper view that will
take the values and add them into the database.

General story:
I want a user to be able to classify their friends in a variety of
ways and save that as a relationship.

Here’s what I have in my model (all code is based on wiki example):

def self.factory(type = nil, params = nil)
case type
when “Family”
return Family.new(params)
when “Contact”
return Contact.new(params)
when nil
return Friend.new(params)
end

This is the controller:

def new
@friend = Friend.factory(params[:friend_type])
end

def create
@friend = Friend.factory(params[:friend_type], params[:friend])
if @friend.save
flash[:notice] = ‘Friend was successfully created.’
redirect_to :action => ‘list’
else
render :action => ‘new’
end
end

I have absolutely no idea how to create a view that will take these
values and add them to the database. I tried stuff like:

<%= start_form_tag :action => ‘create’ %>
<%= render :partial => ‘form’ %>

<%= select (:friend, :create, :friend_type, %w{ Soulmate Family }) %>

<%= submit_tag “Create” %>
<%= end_form_tag %>

The STI wiki says add:

<%= hidden_field_tag “person_type”, @person[:type] %>

but this makes no sense to me. I’ve basically been taking stabs in
the dark. It would be nice if someone can point me in the right
direction for understanding views as well. Again, my apologies for
asking all this basic stuff.

Sam