# Passing values trough models

**URL:** <https://www.ruby-forum.com/t/passing-values-trough-models/122280>\
**Category:** Rails\
**Created:** [December 6, 2007, 4:44am UTC](https://www.ruby-forum.com/t/passing-values-trough-models/122280 "2007-12-06T04:44:25Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![nad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@nad](https://www.ruby-forum.com/u/nad)\
**Post date:** [December 6, 2007, 4:44am UTC](https://www.ruby-forum.com/t/passing-values-trough-models/122280/1 "2007-12-06T04:44:25Z")

</div>

Hi all,

i have a form and the form is validating correctly. the relevant table  
to this model has a coloum to store a some text(a auto generated text.).  
to store text to this coloum i am not giving it from a normal form.  
instead of that i want to pass a values to this model from a another  
different model so it can save in the table.

pls any one know how to archive this task.

Thank  
Nadeesha

---

<div class="post-metadata">

**Author:** ![nad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@nad](https://www.ruby-forum.com/u/nad)\
**Post date:** [December 6, 2007, 9:17pm UTC](https://www.ruby-forum.com/t/passing-values-trough-models/122280/2 "2007-12-06T21:17:02Z")

</div>

So if I understand you correctly, it sounds like you have two models:  
A and B. Model A has an attribute that allows text to be stored in it,  
and this attribute is populated by model B. So, what you want to do  
is:

class B \< ActiveRecord::Base

# id: the id of the record where the text should be stored

# text: the text to be stored

def populate\_text\_field(id, text)  
if a = A.find(id)  
a.update\_attribute(:text\_field, text)  
end  
end

end

Is this what you are intending?

On Dec 5, 8:44 pm, Nadeesha M. \<rails-mailing-l…@andreas-

---

<div class="post-metadata">

**Author:** ![nad](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/n/ed8c4c/32.png) [@nad](https://www.ruby-forum.com/u/nad)\
**Post date:** [December 7, 2007, 5:03am UTC](https://www.ruby-forum.com/t/passing-values-trough-models/122280/3 "2007-12-07T05:03:11Z")

</div>

Matt W. wrote:

> So if I understand you correctly, it sounds like you have two models:  
> A and B. Model A has an attribute that allows text to be stored in it,  
> and this attribute is populated by model B. So, what you want to do  
> is:
> 
> class B \< ActiveRecord::Base
> 
> # id: the id of the record where the text should be stored
> 
> # text: the text to be stored
> 
> def populate\_text\_field(id, text)  
> if a = A.find(id)  
> a.update\_attribute(:text\_field, text)  
> end  
> end
> 
> end
> 
> Is this what you are intending?
> 
> On Dec 5, 8:44 pm, Nadeesha M. \<rails-mailing-l…@andreas-

Hi

Thanks for the tip. i think ur solution can help me to archive the  
solution i want.

Thanks  
Nadeesha
