Here are the available Rails validation filters: before_validation_on_update before_validation_on_create validate validate_on_update validate_on_create after_validation after_validation_on_update after_validation_on_create before_save before_update before_create after_update after_create after_save These filters are callbacks that are invoked automatically. The difference between update and create is really with respect to the database. If the record you are saving is a new record in the db, then it means you are creating. If the item already exists but you are making a change, then it means you are updating. In other words, it does not matter, whether you called obj.save or obj.create, before_update filter will be invoked. The same is true for obj.save vs. obj.update_attributes. So no matter what Active record method you invoke the filter is decided based on the database record. How about before_save, before_after_save? They will always be invoked whether you are creating or updating....
I read and played with WebClient and HttpWebRequest classes. Both of these classes allow you to make requests to an http server. Once you make the request, you give a callback that is invoked once the response is received so you can happily examine the response. Let's say your HTTP server is streaming a file, or it wants to hold on to your request and sends messages as necessary from the same connection. To be able to work with such a server, your http client must be able to read the data as soon as it is available without requiring the response to be received completely. After searching silverlight forums I found a solution. The solution assumes that you have a control on the server code or the response you are getting is bigger than 4KB (IE buffers upto 4KB). Here is the code snipped for your client side: HttpWebRequest request = (HttpWebRequest)WebRequest.Create(uri); request.Method = "POST"; request.AllowReadStreamBuffering = false; try { request.BeginGetResponse(On...
Given that: TestABC.java is located at: test/x/y/z/TestABC.java testdata.txt is located at: resources/x/y/z/TestABC/testdata.txt classpath includes resources folder We are trying to read the testdata.txt from TestABC.java. We need a location independent way to point to these files. Therefore, we would like to use getResource() method of a Class or ClassLoader. Here are the correct ways: 1: this.getClass().getClassLoader().getResource("x/y/z/TestABC/testdata.txt"); 2: this.getClass().getResource("/x/y/z/TestABC/testdata.txt")); 3: this.getClass().getResource("TestABC/testdata.txt")); Explanation: 1: works because ClassLoader takes the path as it is (no manipulation) and search in the classpath folders. In this case, it will go to the resources folder and it will find the testdata.txt file in the given path. 2: works because Class.getResource takes the "absolute" path, removes its starting / and t...
Comments