u didnt tell me how can we add in the create action at the same time
for people table
can u send me the code how can we add or an idea of that?
On Oct 3, 3:47 am, Daniel <[EMAIL PROTECTED]> wrote:
> On Oct 3, 8:22 am, Daniel <[EMAIL PROTECTED]> wrote:
>
> > Hi Cool,
> > This post didn't make it onto ruby-forum.com but it is on google.
>
> > On Oct 2, 11:10 pm, cool <[EMAIL PROTECTED]> wrote:
>
> > > 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| %>
>
> Sorry. form_for is handy; whether you're passing the parameter in or
> not.
> It will generate an authenticity token as well as just being more
> convenient.
> Read up on api.rubyonrails.com. See also form_tag.
>
> > > <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
> > > [EMAIL PROTECTED] = Student.new
> > > [EMAIL PROTECTED] = 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
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Ruby
on Rails: Talk" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/rubyonrails-talk?hl=en
-~----------~----~----~----~------~----~------~--~---