operation on data for model

you can handle this all in the model

since i don't know your attribute names, i'll just use simple ones,
foo, bar and the unique id attribute will be unique_ident

class Model < AR::Base

  before_create :generate_unique_ident

  def generate_unique_ident
    unique_ident = foo + bar + self.generate_some_number

  def self.generate_some_number

  validates_presence_of :foo
  validates_presence_of :bar

then just save your model as usual

sorry, you've confused me.

foo and bar where my mock columns on your model. i don't understand
where this bar table is coming from.

perhaps you need to provide more info on your situtation.

well, what you could do in this case is just make it a 'psuedo
attribute' and you don't even have to store it in the database

class Product

  def unique_ident
    category.category_code + product_code

so in this example say you have

id: 1
product_code: 333
category_id: 2

id: 2
category: cars
category_code: ca

p = Product.find(1)
p.unique_ident # => "ca333"