Can someone please help. I do HTTP POST with 3 data items the log below shows they are recognised but the save into the table is enterng NULs. Indeed a query on the db then shows a bunch of NULs. Why isn''t the correct paramer data not being entered? Thanks very much if you can help. Processing ClientsController#create (for 192.168.2.101 at 2008-01-24 21:34:46) [POST] Session ID: 62a7094f0366f46f4a6c6702a08763ac Parameters: {"waypoints"=>"petem", "action"=>"create", "landtitle"=>"blah", "controller"=>"clients", "owner"=>"petem"} ^[[4;36;1mClient Columns (0.001285)^[[0m ^[[0;1mSHOW FIELDS FROM clients^[[0m ^[[4;35;1mSQL (0.000165)^[[0m ^[[0mBEGIN^[[0m ^[[4;36;1mSQL (0.000411)^[[0m ^[[0;1mINSERT INTO clients (`waypoints`, `landtitle`, `owner`) VALUES(NULL, NULL, NULL)^[[0m ^[[4;35;1mSQL (0.007088)^[[0m ^[[0mCOMMIT^[[0m Redirected to http://localhost:3000/clients/73 Completed in 0.01897 (52 reqs/sec) | DB: 0.00895 (47%) | 302 Found [http://localhost/clients] --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Please post your controller method -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jan-24 20:40 UTC
Re: POST params recognised but NULs entered in table?
On 24 Jan 2008, at 20:30, petem wrote:> > Can someone please help. I do HTTP POST with 3 data items the log > below shows they > are recognised but the save into the table is enterng NULs. Indeed a > query on the db then shows a bunch of NULs. Why isn''t the correct > paramer data not being entered? Thanks very much if you can help. > >Well where it''s going wrong is either the controller or the model, but you haven''t shown us either of those :-) Fred> Processing ClientsController#create (for 192.168.2.101 at 2008-01-24 > 21:34:46) [POST] > Session ID: 62a7094f0366f46f4a6c6702a08763ac > Parameters: {"waypoints"=>"petem", "action"=>"create", > "landtitle"=>"blah", "controller"=>"clients", "owner"=>"petem"} > ^[[4;36;1mClient Columns (0.001285)^[[0m ^[[0;1mSHOW FIELDS FROM > clients^[[0m > ^[[4;35;1mSQL (0.000165)^[[0m ^[[0mBEGIN^[[0m > ^[[4;36;1mSQL (0.000411)^[[0m ^[[0;1mINSERT INTO clients > (`waypoints`, `landtitle`, `owner`) VALUES(NULL, NULL, NULL)^[[0m > ^[[4;35;1mSQL (0.007088)^[[0m ^[[0mCOMMIT^[[0m > Redirected to http://localhost:3000/clients/73 > Completed in 0.01897 (52 reqs/sec) | DB: 0.00895 (47%) | 302 Found > [http://localhost/clients] > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> Well where it''s going wrong is either the controller or the model, but > you haven''t shown us either of those :-)Sorry, it''s standard code from controller as per ... # POST /clients # POST /clients.xml def create @client = Client.new(params[:client]) respond_to do |format| if @client.save flash[:notice] = ''Client was successfully created.'' format.html { redirect_to client_url(@client) } format.xml { head :created, :location => client_url(@client) } else format.html { render :action => "new" } format.xml { render :xml => @client.errors.to_xml } end end end --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
okay please post the new action and your form template -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
that is to say The error is obvious but those file will help point it out -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jan-24 21:00 UTC
Re: POST params recognised but NULs entered in table?
On 24 Jan 2008, at 20:48, petem wrote:> >> Well where it''s going wrong is either the controller or the model, >> but >> you haven''t shown us either of those :-) > > Sorry, it''s standard code from controller as per ... > > # POST /clients > # POST /clients.xml > def create > @client = Client.new(params[:client]) >Your form''s not right (or at least not in sync with your controller): your controller is expecting stuff in params[:client] but from your log the parameters for client were right at the top level of params. Fred> respond_to do |format| > if @client.save > flash[:notice] = ''Client was successfully created.'' > format.html { redirect_to client_url(@client) } > format.xml { head :created, :location => > client_url(@client) } > else > format.html { render :action => "new" } > format.xml { render :xml => @client.errors.to_xml } > end > end > end > > > >--~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
"those file"? --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
I''m having the same problems: Processing LabelsController#create (for 127.0.0.1 at 2008-01-24 15:53:01) [POST] Session ID: b34c741748c8da668ea66c5c2c9d639d Parameters: {"name"=>"system1", "memory"=>"2048", "serial"=>"12345", "date"=>"2008-01-24", "action"=>"create", "controller"=>"labels", "processor"=>"intel"} ←[4;35;1mLabel Columns (0.000000)←[0m ←[0mSHOW FIELDS FROM `labels`←[0m ←[4;36;1mSQL (0.000000)←[0m ←[0;1mBEGIN←[0m ←[4;35;1mLabel Create (0.000000)←[0m ←[0mMysql::Error: #23000Column ''date'' cannot be null: INSERT INTO `labels` (`name`, `memory`, `serial`, `date`, `processor`) VALUES('''', '''', '''', NULL, '''')←[0m ←[4;36;1mSQL (0.000000)←[0m ←[0;1mROLLBACK←[0m I am using the standard scaffolded POST method in the controller, and the model is blank, as per scaffolding. Creating new objects works from the web interface, but these values are being submitted from an external ruby script: require ''net/http'' Net::HTTP.start(''localhost'', 3000) do |query| print query.post("/labels", "name=#{ENV[''computername'']}&serial=1234&date=2008-01-24&processor=intel&memory=2048").body end The only change I have made from the scaffolding is to turn off the authentication token by putting protect_from_forgery :except => [:create] in the controller. Any ideas? Thanks. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@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 -~----------~----~----~----~------~----~------~--~---
Oh ... just a noob at this, I perhaps have the wrong idea. I have no form as such since the idea is that this be on the receivng end of a HTTP request (REST etc). The "new" is in the Client''s ActiveRecord subclass. Is totally overboard? BTW if I do access the /clients page via a browser, I''m able to manage the table quite well as expected, but my aim for for unattended HTTP requests to be serviced. Ta for now. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Well Ian, seems we''re on our own for now. Look, I''m just a noobie and I''ve been coming back to this problem several times over the last weeks and I''m out of ideas. Looks like an internal RoR bug to me but no one else seems bothered. If you make any progess could you please share it. Thanks. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Frederick Cheung
2008-Jan-25 01:27 UTC
Re: POST params recognised but NULs entered in table?
On 25 Jan 2008, at 00:23, petem wrote:> > Well Ian, seems we''re on our own for now. > > Look, I''m just a noobie and I''ve been coming back to this problem > several times over the last weeks and I''m out of ideas. Looks like an > internal RoR bug to me but no one else seems bothered. If you make any > progess could you please share it. Thanks.It''s not a rails bug, it''s just a mismatch between the data your controller is expecting and the data you''re giving it the url Ian is hitting is name = #{ENV [''computername '']}&serial=1234&date=2008-01-24&processor=intel&memory=2048 This means that the params hash is :name => ''computer_name'', :serial =>1234, :date => ''2008-01-24'', :processor => ''intel'', ''memory'' => 2048 In your case, as the logs show the params hash is {"waypoints"=>"petem", "action"=>"create", "landtitle"=>"blah", "controller"=>"clients", "owner"=>"petem"} So if you do params[:client] you get nothing. You either need to change your controller to do Client.create(params), or change the url you''re hitting. a url of client[waypoints]=petem&client[landtitle]=blah will result in a params hash with params[:client] containing useful stuff. In terms of figuring this out for yourself, just stepping through your controller in the debugger should have got you there. Fred --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
That does it for me Fred. Thanks very, very much. --~--~---------~--~----~------------~-------~--~----~ 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-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Thanks for pointing out the error of my ways Fred. Just as a follow-up to anyone down the line who has this problem, I''ll explain how I fixed it for my app. First I spent some time building a new constructor for my model that accepted a flat array as an initializer. Then I said, no, this really belongs in the controller. But after I thought about making a new model object in the controller and jamming things into it, I said, that''s kind of ugly too. Really, what if I want to pass the controller two model objects at the same time down the line? The way the Rails team intended it is right, the submitter just needs to indicate what model object it is sending parameters for. So I extended the Hash class like so: class Hash def to_controller_post(controller) str = "" self.each { |key,value| str << "#{controller}[#{key}]=#{value}&" } str.chop #Remove trailing ''&'' end end Now my submit code looks like this: def getAuditData { "name" => ENV[''computername''], "username" => ENV[''username''], "serial" => getSerialNumberBIOS, "processor" => getProcessorName, "memory" => getSystemMemory, "image" => getImageVersion } end Net::HTTP.start(''localhost'', 3000) do |query| query.post("/labels", audit_data.to_controller_post(''label'')).body end It produces URLs formed like this: http://localhost:3000/labels?label[name]=labelsystem1&label[username]=bob.smith&label[serial]=12345&label[processor]=Intel&label[memory]=2048&label[image]=30 This works fine. If you are implementing this in your own code, do remember that you will need to turn authentication token off for the create action by putting protect_from_forgery :except => [:create] in your controller definition. As a final note, I would be using the debugger, but I can''t get the gem installed under win32 because it requires Visual c++ 6.0 to compile, which is not a free download. A little while back I wrestled with trying to get it to compile under Visual C++ 9.0 Express, which is free, but never got it working. Anyone happen to have a plug-and-play debugger solution for win32? Thanks again all. -- 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 rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---