Ruby Forum Ruby on Rails > Passing a value fails [when sending emails]

Posted by Dag Stensson (kaizerkaizer)
on 24.04.2008 13:42
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 <do-not-reply@currant.se>'
    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/1.1" 200 520
http://localhost:3000/presentation?login=dagstensson%40hotmail.com -> /
email/correspond?login=dagstensson%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/1.1" 200 520
http://localhost:3000/presentation?login=dagstensson%40hotmail.com -> /
email/correspond?login=dagstensson%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
-> /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.
Posted by Dag Stensson (kaizerkaizer)
on 24.04.2008 14:11
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/1.1" 200 520
> http://localhost:3000/presentation?login=dagstensson%40hotmail.com -> /
> email/correspond?login=dagstensson%40hotmail.com

but not what comes directly after
Posted by Kyle (Guest)
on 24.04.2008 20:25
(Received via mailing list)
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 Stensson <rails-mailing-l...@andreas-s.net>