my models borrower ----- has_many :loans loan ----- belongs_to :borrower my loans _controller def new @borrower = Borrower.find(params[:borrower_id]) logger.debug '' @borrower.id'' logger.debug @borrower.id @loan = Loan.new respond_to do |format| format.html # new.html.erb format.xml { render :xml => @loan } end end def create logger.debug '' @borrower.id'' logger.debug @borrower.id @loan = Loan.new(params[:loan]) respond_to do |format| if @loan.save format.html { redirect_to(@loan, :notice => ''Loan was successfully created.'') } format.xml { render :xml => @loan, :status => :created, :location => @loan } else format.html { render :action => "new" } format.xml { render :xml => @loan.errors, :status => :unprocessable_entity } end end end in my views i am passing value like this <%= link_to ''New Loan'', :controller => ''loans'', :action => ''new'', :borrower_id => @borrower.id %> every thing working fine in Action new logger.debug @borrower.id Gives id but on create it does not shows anything Where i am wrong and did something i missed i wanna save @borrower.id in @loans.borrower_id Please help thanks in advance -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
If the issue is in the create action please provide the corresponding code. Model code would be helpful too. Luke On Sep 4, 5:51 am, ashu <rajeevsharm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> my models > > borrower ----- has_many :loans > loan ----- belongs_to :borrower > > my loans _controller > > def new > @borrower = Borrower.find(params[:borrower_id]) > logger.debug '' @borrower.id'' > logger.debug -1gG7K0AJqDiez0ei9/+7zw@public.gmane.org > @loan = Loan.new > > respond_to do |format| > format.html # new.html.erb > format.xml { render :xml => @loan } > end > end > > def create > logger.debug '' @borrower.id'' > logger.debug -1gG7K0AJqDiez0ei9/+7zw@public.gmane.org > @loan = Loan.new(params[:loan]) > respond_to do |format| > if @loan.save > format.html { redirect_to(@loan, :notice => ''Loan was > successfully created.'') } > format.xml { render :xml => @loan, :status > => :created, :location => @loan } > else > format.html { render :action => "new" } > format.xml { render :xml => @loan.errors, :status > => :unprocessable_entity } > end > end > end > > in my views i am passing value like this > > <%= link_to ''New Loan'', :controller => ''loans'', :action => > ''new'', :borrower_id => @borrower.id %> > > every thing working fine in Action new logger.debug > @borrower.id Gives id > but on create it does not shows anything > Where i am wrong and did something i missed i wanna save @borrower.id > in @loans.borrower_id > Please help thanks in advance-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com. For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
I have two modelds 1. loan model belongs_to :borrower 2. borrower model has_many:loans In my borrower Show method i wrote <%= link_to ''Request New Loan'', :controller => ''loans'', :action => ''new'', :id => @borrower.id %> my loans_controller have this def new @borrower = Borrower.find(params[:id]) @loan = Loan.new respond_to do |format| format.html # new.html.erb format.xml { render :xml => @loan } end end def create @loan = Loan.new(params[:loan]) @borrower = Borrower.find(params[@borrower_id]) respond_to do |format| if @loan.save format.html { redirect_to(@loan, :notice => ''Loan was successfully created.'') } format.xml { render :xml => @loan, :status => :created, :location => @loan } else format.html { render :action => "new" } format.xml { render :xml => @loan.errors, :status => :unprocessable_entity } end end end On loan create Giving error can not find borrower without an id but on new method''si am getting borrower id prints very well . where i am wrong On Sat, Sep 4, 2010 at 8:18 PM, Luke Cowell <lcowell-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> If the issue is in the create action please provide the corresponding > code. Model code would be helpful too. > > Luke > > On Sep 4, 5:51 am, ashu <rajeevsharm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > my models > > > > borrower ----- has_many :loans > > loan ----- belongs_to :borrower > > > > my loans _controller > > > > def new > > @borrower = Borrower.find(params[:borrower_id]) > > logger.debug '' @borrower.id'' > > logger.debug @borrower.id > > @loan = Loan.new > > > > respond_to do |format| > > format.html # new.html.erb > > format.xml { render :xml => @loan } > > end > > end > > > > def create > > logger.debug '' @borrower.id'' > > logger.debug @borrower.id > > @loan = Loan.new(params[:loan]) > > respond_to do |format| > > if @loan.save > > format.html { redirect_to(@loan, :notice => ''Loan was > > successfully created.'') } > > format.xml { render :xml => @loan, :status > > => :created, :location => @loan } > > else > > format.html { render :action => "new" } > > format.xml { render :xml => @loan.errors, :status > > => :unprocessable_entity } > > end > > end > > end > > > > in my views i am passing value like this > > > > <%= link_to ''New Loan'', :controller => ''loans'', :action > => > > ''new'', :borrower_id => @borrower.id %> > > > > every thing working fine in Action new logger.debug > > @borrower.id Gives id > > but on create it does not shows anything > > Where i am wrong and did something i missed i wanna save @borrower.id > > in @loans.borrower_id > > Please help thanks in advance > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. > >-- Thanks: Rajeev sharma -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
On 6 September 2010 05:30, rajeevsharma86 <rajeevsharma86-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > > > > > > > > > > > > > > > > > > > > > > > > > > > > > > I have two modelds > 1. loan model belongs_to :borrower > > 2. borrower model has_many:loans > > In my borrower Show method i wrote > > <%= link_to ''Request New Loan'', :controller => ''loans'', :action => ''new'', :id => @borrower.id %> > > > my loans_controller have this > def new > @borrower = Borrower.find(params[:id]) > > @loan = Loan.new > > respond_to do |format| > format.html # new.html.erb > format.xml { render :xml => @loan } > > end > end > > def create > > @loan = Loan.new(params[:loan]) > > @borrower = Borrower.find(params[@borrower_id]) > >Compare this line to the equivalent line in the new action. What is the @ doing inside the []? I don''t know whether it should be borrower_id or not, that depends on what params are being passed. Look in the log to see what the params are when you click on create. Colin> > respond_to do |format| > > if @loan.save > > format.html { redirect_to(@loan, :notice => ''Loan was successfully created.'') } > > format.xml { render :xml => @loan, :status => :created, :location => @loan } > > else > format.html { render :action => "new" } > > format.xml { render :xml => @loan.errors, :status => :unprocessable_entity } > > end > end > end > > On loan create Giving error can not find borrower without an id but on new method''si am getting borrower id prints very well . > where i am wrong > > > > On Sat, Sep 4, 2010 at 8:18 PM, Luke Cowell <lcowell-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> If the issue is in the create action please provide the corresponding >> code. Model code would be helpful too. >> >> Luke >> >> On Sep 4, 5:51 am, ashu <rajeevsharm...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> > my models >> > >> > borrower ----- has_many :loans >> > loan ----- belongs_to :borrower >> > >> > my loans _controller >> > >> > def new >> > @borrower = Borrower.find(params[:borrower_id]) >> > logger.debug '' @borrower.id'' >> > logger.debug @borrower.id >> > @loan = Loan.new >> > >> > respond_to do |format| >> > format.html # new.html.erb >> > format.xml { render :xml => @loan } >> > end >> > end >> > >> > def create >> > logger.debug '' @borrower.id'' >> > logger.debug @borrower.id >> > @loan = Loan.new(params[:loan]) >> > respond_to do |format| >> > if @loan.save >> > format.html { redirect_to(@loan, :notice => ''Loan was >> > successfully created.'') } >> > format.xml { render :xml => @loan, :status >> > => :created, :location => @loan } >> > else >> > format.html { render :action => "new" } >> > format.xml { render :xml => @loan.errors, :status >> > => :unprocessable_entity } >> > end >> > end >> > end >> > >> > in my views i am passing value like this >> > >> > <%= link_to ''New Loan'', :controller => ''loans'', :action >> => >> > ''new'', :borrower_id => @borrower.id %> >> > >> > every thing working fine in Action new logger.debug >> > @borrower.id Gives id >> > but on create it does not shows anything >> > Where i am wrong and did something i missed i wanna save @borrower.id >> > in @loans.borrower_id >> > Please help thanks in advance >> >> -- >> 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org >> To unsubscribe from this group, send email to >> rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> >> . >> For more options, visit this group at >> http://groups.google.com/group/rubyonrails-talk?hl=en. >> >> > > > -- > Thanks: > Rajeev sharma > > > -- > 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org<rubyonrails-talk%2Bunsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org> > . > For more options, visit this group at > http://groups.google.com/group/rubyonrails-talk?hl=en. >-- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.