I have two tables A and B
I have saved a record in table A and I want to save the id of that record in table B. How Can I do that.
Well I can do by search of same params which I save in Table A but I feel it is not that good approach.
If the app is has multiple users than that is not good way can any one help to do it better.
if @whatever.save@whatever.reload@another_thing.whatever_id = @whatever.id@another_thing.save
end
That would only be true in a create method, because the ID isn't known until after the thing is saved. But if your relationships are declared in the usual way (has_many, belongs_to, etc.) then this plumbing is taken care of for you in most cases.
As I suggested a little while ago when you first asked this question,
but did not reply to my response, you should consider doing this using
an association between the tables. Something like table_b belongs_to
table_a, table_a has_many table_bs. Then rails will do a lot of the
hard work for you. Almost always in rails if you are manipulating id
values then you are doing it wrong.