I have a model Store with attributes user_id, product_id and token_string.
In the form I collect values for user_id and product_id but not token_string because it is going to be generated after user_id and product_id are saved.
So in the create action the @store is saved normally with only two attributes values and nil token_string.
But right after @store is saved i want to generate a random token_string(doesn’t matter how) and save it to the database on the same row as product_id and user_id where there is nil(i am not sure if update_attribute would do).But the biggest challenge is there is a number from a variable i have to multiply to token generation.
So lets say the number is 2
That means i would generate two token_strings and both have to be saved to the same user_id and product_id.How do i go around this?
Thank you in advance
def create
@quantity=2
@store=Store.new(params[:store])
if @store.save
@quantity.times{ generate token string}
#Then save both generated tokens to the same user_id and product_id
redirect_to :controller=>"products",:action=>"index"
else
redirect_to :action=>"new"
end
end
if you need to save token_string in the same record
but if you need to duplicate the @store with the same user_id and product_id that method can be helpful