Your change from . to :: is a red herring. The method call semantics of . and :: are the same. The error means that your CreateUri class is not being loaded. Check the way it is loaded (by Rails autoloading, by a require statement, etc).
Also, I would have structured the url creation class differently. First, CreateUri is a poor class name because it is too generic. Second, passing an integer (the vehicle id) would require the CreateUri class to know far too much about what that integer represents, thus coupling it conceptually to the Vehicle class. These problems are apparent in the need for the awkward method name "bit_ly_for_vehicle". The Bitly url generator should accept a url and return a url, as this is the interface provided by the service itself (bit.ly's API). Given that the Bitly API requires authentication, I would prefer something like: Bitly.new(username, api_token).shorten(url_for(@vehicle)).short_url "Shorten the url for the vehicle" reveals the code's intention nicely. In fact, and speaking of reuse, this is precisely what the Bitly gem provides (http://github.com/philnash/bitly). This does not address performance and reliability concerns with the network, the Bitly service and etc., but it is at least a good start. Also, do note that this will require url_for in your model. Google should tell you how to make this happen. On Jan 5, 1:29 am, Quee WM <[email protected]> wrote: > Back for some more help. > > I added the following code to the model of the vehicle > > class Vehicle < ActiveRecord::Base > after_save :update_bit_ly_url > > def update_bit_ly_url > bit_ly_url = CreateUri::bit_ly_for_vehicle(self.id) > puts bit_ly_url > end > end > > had to change CreateUri. to CreateUri:: as it was not recognizing > CreateUri. > > maybe I have not written the class properly or have not included it in > the correct manner. > > Now this is the error i get. > > NameError (uninitialized constant Vehicle::CreateUri): > app/models/vehicle.rb:22:in `update_bit_ly_url' > app/controllers/vehicles_controller.rb:46:in `create' > > Any ideas? > -- > Posted viahttp://www.ruby-forum.com/. Rein Henrichs http://reinh.com | http://reductivelabs.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 [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.

