Passing instance variable between controllers

Hello,
I have two controllers mailinglist_controller and
mailtemplate_controller
The mailinglist controller has an instance variable @mailinglist.

how can I to use the instance variable @mailinglists from controller
mailinglist_controller in mailtemplate_controller.?

The control goes as follows

http://localhost:3000/mailinglist/mailinglists
This displays the lists. The user selects the lists by ticking
checkboxes
and then clicks the “write mail” button

http://localhost:3000/mailinglist/getmailinglists
The function getmailinglists in the mailinglist controller gets all the
mailinglist selected by the user and stores them in @mailinglists
instance variable.The last line in the getmailinglists function is

render :action=>“write_mail”

This brings the user to the page where there is a text box wherethe user
can type in the mail content.

after the user clicks on “send mail” button
the control goes to
http://localhost:3000/mailtemplate/sendmail

I need to access the @mailinglists values that i had before in the
mailinglist controller. How can i do that. The sendmail function is
below…The @mailinglists returns nil at present because the values are
not retained from the previous controller.

def sendmail
@mailinglists.each do |ml1|

@people =
Person.find(:all,:include=>:mailinglists,:conditions=>[‘mailinglist_id =
?’,ml1.id])
@people.each do|person|
UserMailer.deliver_send_mail(person,params[:textarea])
end
end
render :action=>“…/mailinglist/send_mail”
return
end

On 12/30/07, Ank Ag [email protected] wrote:

Hello,
I have two controllers mailinglist_controller and
mailtemplate_controller
The mailinglist controller has an instance variable @mailinglist.

how can I to use the instance variable @mailinglists from controller
mailinglist_controller in mailtemplate_controller.?

You don’t, normally. An instance variable is not persistent across
requests. You can store it in a session to make it persistent or you
can pass it in the urls.

You can add a finder that brings the instance variable into existence,
then share that finder method with both controllers by placing it in
app/controllers/application.rb.


Greg D.
http://destiney.com/