I wonder if @b.save is returning false?  Maybe a validation issue?
Have you tried throwing a debugger statement in there?

On May 28, 7:09 am, Vipin <[email protected]> wrote:
> hi
> I am facing a problem. I have two models A and B which have relations
> as follows
>
> A has_one B
> B belongs_to A
>
> Now I want to ensure that whenever an 'A' record is created,
> automatically a 'B' record is also created.
> I was trying to achieve this by doing the following but it is not
> making the entry in B table, otherwise code runs fine without any
> errors.
>
> what can be the reason. ??
>
> class AController < ApplicationController
>
> def create
>     @a = A.new(params[:a])
>
>     respond_to do |:a|
>       if @a.save
> ##### NEW CODE  - THIS IS WHAT I HAVE ADDED
>         @b = B.new
>         @b.a_id = @a.id
>         @b.save
> #### NEW CODE END
>
>         flash[:notice] = 'A was successfully created.'
>         format.html { redirect_to(@a) }
>         format.xml  { render :xml => @a, :status
> => :created, :location => @a }
>       else
>         formatat.html { render :action => "new" }
>         format.xml  { render :xml => @a.errors, :status
> => :unprocessable_entity }
>       end
>     end
>   end
>
> end
>
> vipin
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to