On Oct 3, 3:15 pm, cool <[EMAIL PROTECTED]> wrote:
> 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?
>
For the controller and the html form, nothing is stopping you from
editing and creating multiple Person objects (Student, Parent, or
Principal) within the one action. Get familiar with rails form
helpers as mentioned previously.
Here's a tip: think in terms of the 'name' attribute in your form:
If it's
<input name="student[first_name]" value="fred" type="text" ... />
then you'll get
params[:student][:first_name] => 'fred'
in your controller (when you submit).
Similarly for
<input name="parent[first_name]" ... />
you'll get
params[:parent][:first_name]
I've also mentioned how to generate a dropdown instead of a text field
if you want to assign an existing parent to a student.
Then when this form is submitted to your controller you would have
something like:
def update
@student=Student.new(params[:student])
# If you are assigning parent to student.
@student.parent_id = params[:parent][:id] ## if you have dropdown
@student.save!
...
## If you are creating the parent alongside the student..
@parent=Parent.new(params[:parent])
@parent.save!
...
end
Find some tutorials, read the main pages at api.rubyonrails.com and
buy the rails book
http://www.pragprog.com/titles/rails2/agile-web-development-with-rails
. If you're having trouble with rails basics, maybe skip STI for a
bit and just use separate classes.
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
-~----------~----~----~----~------~----~------~--~---