On Thu, Oct 29, 2009 at 2:23 AM, Misiek Sz <[email protected]> wrote: > > Leonardo Mateo wrote: >> On Sun, Oct 25, 2009 at 3:23 PM, Misiek Sz >> <[email protected]> wrote: >>> saved when the form is submitted? >> OK, now the situation is clearer for me. There's something you're not >> getting from associations, let's see if with the example you get it >> more clear. >> If you want to create the association when you create the education >> plan, why would you try to get it on the get_info action and not on >> the create action? >> When you get (render) the student info on the create form for >> education plan, you should keep the student id and send it with the >> rest of the education plan parameters as the >> education_plan[student_id]. >> Then, in the create action, you can do >> EducationPlan.new(params[:education_plan]) (or whatever your params >> are called) and, if you have the right student_id the relationship >> should be created automatically. >> >> If it doesn't work, you should "pastie" your code so we can debug it >> better. >> >> Hope it helps. >> >> -- >> Leonardo Mateo. >> There's no place like ~ > was on the road past two days..... > I want to do exactly what you are saying Leonardo. > Here is my code for > education_plans_controller.rb > ---------------------------- > def create > �...@education_plan = EducationPlan.new(params[:education_plan]) > # this is my sneaky way around, which I don't want to use....You'll see > what i'm doing when you see the view I think that with this is enough.
> # �...@student = Student.find(params[:student_id]) > # �...@tutor = Tutor.find(params[:tutor_id]) > # �...@education_plan.student = @student > # �...@education_plan.tutor = @tutor You have you tutor_id and student_id parameters but you're using them in the wrong way. You should send the parameters inside the params[:education_plan] array. You should receive, in the controller, params[:education_plan][:student_id] and params[:education_plan][:tutor_id] instead of params[:student_id] and params[:tutor_id]. So you need to modify your view to accomplish this. Once you have this, in your controller: @education_plans = EducationPlan.new(params[:education_plan]) will do all the magic with relationships. You don't need to do @education_plan.student = Student.find(student_id) One more thing, if you're testing, you can ensure that behavior in a test and then adjust you application. If you're not testing... well.. you should. Hope it helps. -- Leonardo Mateo. There's no place like ~ --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---

