# Learning how models, controllers, and views pass data

**URL:** <https://www.ruby-forum.com/t/learning-how-models-controllers-and-views-pass-data/64301>\
**Category:** Rails\
**Created:** [January 23, 2006, 2:16am UTC](https://www.ruby-forum.com/t/learning-how-models-controllers-and-views-pass-data/64301 "2006-01-23T02:16:03Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![jpfeifer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/65b543/32.png) [@jpfeifer](https://www.ruby-forum.com/u/jpfeifer)\
**Post date:** [January 23, 2006, 2:16am UTC](https://www.ruby-forum.com/t/learning-how-models-controllers-and-views-pass-data/64301/1 "2006-01-23T02:16:03Z")

</div>

As a noob to Rails and web development in general, I think I still need  
a broader understanding of how Views, Controllers, and Models pass  
information and variables to each other.

I’m creating a site that allows for email campaigns. I have a  
‘create\_email\_controller’:

class Admin::CreateEmailController \< Admin::BaseController  
layout ‘admin’  
def index  
write  
render :action =\> ‘write’  
end

def write  
@email = Email.new  
end

def email\_list  
email = Email.find(:all)  
email.each { |address| MailList::deliver\_send\_email(address) }  
redirect\_to (:action =\> @section)  
end

end

where I want the user to type a message body into a textarea field:

\<%= error\_messages\_for ‘email’ %\>

Message  
\<%= text\_area 'email', 'message' %\>

I want to pass from the form a variable @message to email\_list in the  
controller, which passes to the MailList model:

class MailList \< ActionMailer::Base  
def send\_email(email)  
@recipients = email.address  
@from = ‘removed\_email\_address@domain.invalid’  
@subject = ‘Toro Paintball’  
@body[‘full\_name’] = email.fullname  
## @message in here someway ##  
end  
end

which invokes the view send\_email.rhtml:

Dear \<%= @full\_name %\>,

\<%= @message %\>

Hope this isn’t way too long winded, but is this completely simple to do  
without having to store @message as a session variable or in the DB?  
Can I just take the value of the textarea, pass it through the  
controllers and model to the view like this?

---

<div class="post-metadata">

**Author:** ![jpfeifer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/65b543/32.png) [@jpfeifer](https://www.ruby-forum.com/u/jpfeifer)\
**Post date:** [January 23, 2006, 1:31pm UTC](https://www.ruby-forum.com/t/learning-how-models-controllers-and-views-pass-data/64301/2 "2006-01-23T13:31:17Z")

</div>

In your controller, you can get the message variable with something like  
this :

params[:message]

More generally, params holds all your form’s variables
