Hi Cool,
This post didn't make it onto ruby-forum.com but it is on google.
this is my model
class Person < ActiveRecord::Base
end
class parent < Person
end
class Student < person
end
class principal<person
end
Obviously the above 'person' and 'principal' are capitalized.
i have table called people.
iam adding all the details of parent and student and principal in the
same table.
yes
my form is
<% form_for :student do %>
Not much point doing this if you don't include the parameter. Also,
where is your form posting to?
<% form_for :student , :url => {:action => 'update'} do |s| %>
<td><%= text\_field :first\_name, :label => "Student" %>
<td><%= text\_field :last\_name %></td>
Then you can say:
<td><%= s.text_field :first_name, :label => "Student" %>
Or
<td><%= text_field :student , :first_name, :label => "Student"
%>
which is the same thing.
<% fields\_for :parent %>
You don't need "fields_for" - I don't think you're using it below.
<tr>
<td><%= text\_field :first\_name, :label => "Parents/
Guardian" %></td>
So instead, it would be something like:
<td><%= text_field :parent , :first_name, :label => "Parents/
Guardian" %></td>
And similarly for the rest of these:
<td><%= text\_field :last\_name %></td>
</tr>
<tr>
<td><%= text\_field :email, :label => "Email" %></td>
</tr>
<tr>
<td><%= text\_field :phone, :label => "Phone" %></td>
</tr>
<% end %>
<% end %>
See my previous post if you want a dropdown selection box; ie <%=
select ... %>.
In the New action i have provided like
def new
@student = Student\.new
@parent = Parent\.new
end
ok; you could probably even omit creating these.
my fields in people table are
t.column :type, :string
t.column :first_name, :string
t.column :last_name, :string
t.column :email, :string
t.column :phone, :string
t.column :address, :text
ok
how can we add the student details(first_name, last_name) and the
parent details(first_name, last_name, email, phone) at the same time
with in the same table called people.
So:
<td><%= text_field :parent , :first_name, :label => "Parents/
Guardian" %></td>
will create something like
<input type="text" name="parent[first_name]" ... />
The important thing is the name attribute.
It will be converted to
params[:parent][:first_name]
etc
Similarly for principal:
<td><%= text_field :principal , :first_name %></td>
So in your update action of your controller, you then say:
@parent=Parent.new(params[:parent])
and similarly for @student and @principal.
Regards,
Daniel