I have an odd issue that I am having a difficult time solving. When I attempt to create or edit data in my rails app; it INSERTs NULL values instead of the values I eintered in the form. Same with editing the data; it doesn''t UPDATE the table with values I entered. Via the console, I can see that it recieved the values but the SQL statements show NULL values. I don''t know where my problem lies. Here''s my code below. Any help would be greatly appreciated. Thanks! Console error http://dpaste.com/90452/ meetmes_controller.rb http://dpaste.com/90453/ meetme.rb Model (nothing in here) http://dpaste.com/90454/ meetme view (new) http://dpaste.com/90455/ meetme view (edit) http://dpaste.com/90456/ Michael
Hello Micheal, when using formfor, the returned parameter''s name is the same as the model''s name, but in your create action you are retrieving "meetmes" instead of "meetme" from the parameters (which is nil) so the new method would instantiate an empty model and then try to save it. try this create action instead of the one you have: def create @meetme = Meetme.new(params[:meetme]) # notice this line respond_to do |format| if @meetme.save flash[:notice] = ''Meetmes was successfully created.'' format.html { redirect_to(@meetme) } format.xml { render :xml => @meetme, :status => :created, :location => @meetme } else format.html { render :action => "new" } format.xml { render :xml => @meetme.errors, :status => :unprocessable_entity } end end end Cheers.. On Sep 7, 1:59 am, Michael R <michaelros...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> I have an odd issue that I am having a difficult time solving. > > When I attempt to create or edit data in my rails app; it INSERTs NULL > values instead of the values I eintered in the form. Same with editing > the data; it doesn''t UPDATE the table with values I entered. Via the > console, I can see that it recieved the values but the SQL statements > show NULL values. > > I don''t know where my problem lies. Here''s my code below. Any help > would be greatly appreciated. Thanks! > > Console errorhttp://dpaste.com/90452/ > > meetmes_controller.rbhttp://dpaste.com/90453/ > > meetme.rb Model (nothing in here)http://dpaste.com/90454/ > > meetme view (new)http://dpaste.com/90455/ > > meetme view (edit)http://dpaste.com/90456/ > > Michael
Hassan Schroeder
2009-Sep-07 00:16 UTC
Re: rails inserting NULL values instead of actual values
On Sun, Sep 6, 2009 at 3:59 PM, Michael R<michaelrosejr-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> When I attempt to create or edit data in my rails app; it INSERTs NULL > values instead of the values I eintered in the form.> meetmes_controller.rbdef create @meetme = Meetme.new(params[:meetmes])> meetme view (new)<% form_for(@meetme) do |f| %> Singular/plural mismatch? that is, shouldn''t it be @meetme = Meetme.new(params[:meetme]) # to match your form -- Hassan Schroeder ------------------------ hassan.schroeder-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org twitter: @hassan
Thanks Hasson, cousine! That fixed my problem. I appreciate the quick responses. Michael On Sep 6, 5:04 pm, cousine <alphaeng...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hello Micheal, > > when using formfor, the returned parameter''s name is the same as the > model''s name, but in your create action you are retrieving "meetmes" > instead of "meetme" from the parameters (which is nil) so the new > method would instantiate an empty model and then try to save it. > > try this create action instead of the one you have: > > def create > @meetme = Meetme.new(params[:meetme]) # notice this line > > respond_to do |format| > if @meetme.save > flash[:notice] = ''Meetmes was successfully created.'' > format.html { redirect_to(@meetme) } > format.xml { render :xml => @meetme, :status > => :created, :location => @meetme } > else > format.html { render :action => "new" } > format.xml { render :xml => @meetme.errors, :status > => :unprocessable_entity } > end > end > end > > Cheers.. > > On Sep 7, 1:59 am, Michael R <michaelros...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > > > > I have an odd issue that I am having a difficult time solving. > > > When I attempt to create or edit data in my rails app; it INSERTsNULL > > values instead of the values I eintered in the form. Same with editing > > the data; it doesn''t UPDATE the table with values I entered. Via the > > console, I can see that it recieved the values but the SQL statements > > showNULLvalues. > > > I don''t know where my problem lies. Here''s my code below. Any help > > would be greatly appreciated. Thanks! > > > Console errorhttp://dpaste.com/90452/ > > > meetmes_controller.rbhttp://dpaste.com/90453/ > > > meetme.rb Model (nothing in here)http://dpaste.com/90454/ > > > meetme view (new)http://dpaste.com/90455/ > > > meetme view (edit)http://dpaste.com/90456/ > > > Michael