Quee WM wrote:
> I plan on writing a helper function which will be able to take the id
> for the new record and return the link.

Using a "helper" function implies that the coding will trigger as the 
template is being rendered. If this is the case, you don't need an entry 
in the database. Just write the helper to use the item id to look up the 
item and generate the link from the item information.

However, if the link/URL is needed elsewhere (perhaps outside the Rails 
app) and therefore needs to be stored in the database, then I'd suggest 
you just create an extra field (bit_ly_url perhaps). This is assuming 
that each vehicle has a unique URL.

As for the code that generates the URL - I'd create a custom ruby class 
to do that. Put the code in the lib folder.

So for example, say you create a class CreateURL with a class method of 
bit_ly_for_vehicle, you can then create a vehicle instance method to 
call the CreateURL method and this can be triggered via a call back 
(e.g. before_save)

So

class Vehicle < ActiveRecord::Base
  before_save update_bit_ly_url

  def update_bit_ly_url
    bit_ly_url = CreateURL.bit_ly_for_vehicle(self.id)
  end
end

-- 
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 [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.


Reply via email to