# Passing a value fails \[when sending emails\]

**URL:** <https://www.ruby-forum.com/t/passing-a-value-fails-when-sending-emails/135720>\
**Category:** Rails\
**Created:** [April 24, 2008, 1:42pm UTC](https://www.ruby-forum.com/t/passing-a-value-fails-when-sending-emails/135720 "2008-04-24T13:42:30Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaizerkaizer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/45deac/32.png) [@kaizerkaizer](https://www.ruby-forum.com/u/kaizerkaizer)\
**Post date:** [April 24, 2008, 1:42pm UTC](https://www.ruby-forum.com/t/passing-a-value-fails-when-sending-emails/135720/1 "2008-04-24T13:42:30Z")

</div>

Hi, I’m having trouble with my correspond method (in my  
email\_controller). When I try passing “recipient” to my message method  
(in my UserMailer model) I loose the information placed in the  
“recipient”, resulting in my Params\_posted?(:message) to fail.

##############################################################  
email\_controller  
##############################################################  
def correspond

```
user = User.find(session[:user])

```

puts “\n\n\n correspond\_dump1: user=#{session[:user].to\_i}\n\n\n”

```
recipient = User.find_by_login(params[:login])

```

puts “\n\n\n correspond\_dump2: recipient=#{recipient}\n\n\n”

```
@title = "Email #{recipient.login}"

if param_posted?(:message)

     @message = Message.new(params[:message])
  if @message.valid?
         UserMailer.deliver_message(
       :user => user,
      :recipient => recipient,
      :message => @message,
      :user_url => presentation_for(user),
      :reply_url => url_for(:action => "correspond",
                            :user => user.login)
    )

    flash[:notice] = "Email sent."
    redirect_to :controller => "home", :action => "index"
  end
end

```

end

##############################################################  
UserMailer model  
##############################################################

```
def message(mail)
subject mail[:message].subject
from 'CSCP <removed_email_address@domain.invalid>'
puts "\n\n\n correspond_dump3:

```

UserMailer\_recipient=#{mail[:recipient]}\n\n\n" ### inte user.login =  
fel user , id=0, :recipient=0, :login=0  
recipients mail[:recipient]  
body mail

end

##############################################################  
Application\_Controller  
##############################################################  
def param\_posted?(sym)  
request.post? and params[sym]  
end

##############################################################  
output in console  
##############################################################  
127.0.0.1 - - [24/Apr/2008:10:36:26 VÃµsteuropa, normaltid] “GET /email/  
correspond?login=dagstensson%[40hotmail.com](http://40hotmail.com) HTTP/1.1” 200 520  
[http://localhost:3000/presentation?login=dagstensson%40hotmail.com](http://localhost:3000/presentation?login=dagstensson%40hotmail.com) → /  
email/correspond?login=dagstensson%[40hotmail.com](http://40hotmail.com)

correspond\_dump1: user=60

correspond\_dump2: recipient=#User:0x460ba54

127.0.0.1 - - [24/Apr/2008:10:37:09 VÃµsteuropa, normaltid] “GET /email/  
correspond?login=dagstensson%[40hotmail.com](http://40hotmail.com) HTTP/1.1” 200 520  
[http://localhost:3000/presentation?login=dagstensson%40hotmail.com](http://localhost:3000/presentation?login=dagstensson%40hotmail.com) → /  
email/correspond?login=dagstensson%[40hotmail.com](http://40hotmail.com)

correspond\_dump1: user=60

correspond\_dump2: recipient=

127.0.0.1 - - [24/Apr/2008:10:37:18 VÃµsteuropa, normaltid] “POST /  
email/correspond HTTP/1.1” 500 8823  
[http://localhost:3000/email/correspond?login=dagstensson%40hotmail.com](http://localhost:3000/email/correspond?login=dagstensson%40hotmail.com)  
 → /email/correspond

Now, what you’ve seen above is when I enter the form view and the  
second part is when I hit the submit button to post it. It re-does the  
first part of the code and tries to fetch the recipient but nothing is  
found.

---

<div class="post-metadata">

**Author:** ![kaizerkaizer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/45deac/32.png) [@kaizerkaizer](https://www.ruby-forum.com/u/kaizerkaizer)\
**Post date:** [April 24, 2008, 2:11pm UTC](https://www.ruby-forum.com/t/passing-a-value-fails-when-sending-emails/135720/2 "2008-04-24T14:11:22Z")

</div>

Sorry posted too much from the console, ignore the first  
GET-information:

> 127.0.0.1 - - [24/Apr/2008:10:36:26 VÃµsteuropa, normaltid] “GET /email/  
> correspond?login=dagstensson%[40hotmail.com](http://40hotmail.com) HTTP/1.1” 200 520  
> [http://localhost:3000/presentation?login=dagstensson%40hotmail.com](http://localhost:3000/presentation?login=dagstensson%40hotmail.com) → /  
> email/correspond?login=dagstensson%[40hotmail.com](http://40hotmail.com)

but not what comes directly after

---

<div class="post-metadata">

**Author:** ![kaizerkaizer](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/k/45deac/32.png) [@kaizerkaizer](https://www.ruby-forum.com/u/kaizerkaizer)\
**Post date:** [April 24, 2008, 8:25pm UTC](https://www.ruby-forum.com/t/passing-a-value-fails-when-sending-emails/135720/3 "2008-04-24T20:25:09Z")

</div>

What happens if you replace your custom param\_posted? method with its  
logic in the controller; i.e., use:

if request.post? && params[:message]  
…send message…  
end

Are emails being sent with the GET? …the POST? Neither? Both?  
It’s hard to see what’s going on. Is there an error that you can  
post?

-Kyle

On Apr 24, 7:11 am, Dag S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)
