Hey, I'm trying to achieve something relatively simple and missing
something that is probably very simple, which I'm loosing my head over.
My situation is the following: I have two tables:
-education_plans
-students
Each student has_one ed_plan and each ed_plan belongs to one student.
What I'm trying to achieve is on the form when new ed_plan is created, I
want to have a text box where I can enter st_id(not primary key of the
students table, my own id created for each student). Then the call is
made to the get_student_info method where student info is pulled and
associated with the education plan. This is where the problem is because
I render text or template from get_student_info method fine, but how do
I at the same time associate returned info about the student with
ed_plan.
I've tried number of various combinations and I just can't get it to
work. I'm really hoping you guys can help me out.
So my new view on ed_plans looks like this:
<% form_for(@education_plan) do |f| %>
<%= f.error_messages %>
<table>
<tr>
<td>Student name</td>
<td>Student ID</td>
<td>Grade</td>
</tr>
<tr>
<td><div id="student_info"></div></td>
<td><%=text_field_tag :st_id %></td>
<%= observe_field(:st_id, :frequency => 0.25, :update =>
:student_id,
:url =>{:action => :get_student_info}, :with =>
'st_id') %>
<td><div id="student_grade"></div></td>
</tr>
<tr>
<td><%= f.label :comments %></td>
<td><%= f.text_area(:comments, :cols => 30, :rows => 4) %></td>
</tr>
<tr>
<td><%= f.label :service_code %></td>
<td><%= f.text_field(:service_code, :size =>3) %></td>
</tr>
<tr>
<td><%= f.label :school_number %></td>
<td><%= f.text_field(:school_number, :size =>3) %></td>
</tr>
</table>
<%= f.submit 'Create'%>
the get_student_info methods looks like this:
def get_student_info
@student = Student.find_by_osis(params[:osis])
# @education_plan.student_id = @student
return @student
end
Also, one thing I couldn't get that if I uncomment the line #
@education_plan.student_id = @student I get error method not available
for nil object, which is very weird because that method is in the
EducationPlan controller.
THanks for you help...
--
Posted via http://www.ruby-forum.com/.
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---