NoMethodError undefined method mail for - actionmailer

After setting up mailer (3.2.6) in Ruby on rails (3.2.6) I get this error:
NoMethodError (undefined method `mail' for #):
my user_mailer.rb looks like this:
class UserMailer < ActionMailer::Base
default :from => "test#test.com"
def activation_mail(user)
#user = user
mail(:to => user.mail, :subject => "Registration")
end
end
I followed example provided here: http://guides.rubyonrails.org/action_mailer_basics.html
In configuration file I added this line:
config.action_mailer.delivery_method = :test
I also tried with :smtp and configuration for gmail.
What have I missed?

I had a similar problem recently and rectified it by replacing:
def self.activation_mail()
with
def activation_mail()

you should try replacing
def activation_mail(user)
#user = user
mail(:to => user.mail, :subject => "Registration")
end
with
def activation_mail(user)
#user = user
mail(:to => #user.mail, :subject => "Registration")
end

It's a typo error. Your user.mail doesn't exist. Maybe it should be user.email or something else.

I bet your "user" object you're passing is either 1) not instantiated correctly, or 2) an array instead of an individual User object

I found that a typo in your mailer view can cause this problem. The error message is misleading.

Related

How can I use a local (or per view) variable in Sinatra with Haml partials?

I have a Haml partial in Sinatra to handle all of my 'page open' items like meta tags.
I would love to have a variable for page_title in this partial and then set that variable per view.
Something like this in the partial:
%title #page_title
Then in the view, be allowed to do something like:
#page_title = "This is the page title, BOOM!"
I have read a lot of questions/posts, etc. but I don't know how to ask for the solution to what I am trying to do. I'm coming from Rails where our devs usually used content_for but they set all that up. I'm really trying to learn how this works. It seems like I have to define it and use :locals in some way but I haven't figured it out. Thank you in advance for any tips!
You pass variables into Sinatra haml partials like this:
page.haml
!!!
%html{:lang => 'eng'}
%body
= haml :'_header', :locals => {:title => "BOOM!"}
_header.haml
%head
%meta{:charset => 'utf-8'}
%title= locals[:title]
In the case of a page title I just do something like this in my layout btw:
layout.haml
%title= #title || 'hardcoded title default'
Then set the value of #title in routes (with a helper to keep it short).
But if your header is a partial then you can combine the two examples like:
layout.haml
!!!
%html{:lang => 'eng'}
%body
= haml :'_header', :locals => {:title => #title}
_header.haml
%head
%meta{:charset => 'utf-8'}
%title= locals[:title]
app.rb
helpers do
def title(str = nil)
# helper for formatting your title string
if str
str + ' | Site'
else
'Site'
end
end
end
get '/somepage/:thing' do
# declare it in a route
#title = title(params[:thing])
end

Cucumber (with watir-webdriver): undefined method `confirmation_token'

How cann I use confirmation token in cucumber? I need this to test a registration without to check an e-mail.
My code:
#b.text_field(:name => 'profile[prename]').set 'Kurt'
#b.text_field(:name => 'profile[surname]').set 'Russell'
#b.text_field(:id => 'profile_email').set 'user#trash-mail.com'
#b.text_field(:id => 'profile_password').set 'password'
#b.text_field(:name => 'profile[password_confirmation]').set 'password'
#b.button(:id => 'profile_submit').click
#ctoken = Profile.last.confirmation_token
#b.goto("http://localhost:3000/profiles/confirmation?confirmation_token=#{#ctoken}")
or:
#b.goto("http://localhost:3000/profiles/confirmation?confirmation_token=#{Profile.last.confirmation_token}")
I become: undefined method `confirmation_token' for nil:NilClass (NoMethodError)
Looks to me that Profile.last returns nil in your case, hence the error message undefined method confirmation_token for nil:NilClass (NoMethodError). Please share code where you define Profile.

Sinatra on Thin: How to hide or change HTTP 'Server' response header

What is the cleanest way to do this? Some Rack middleware? I tried to modify env['SERVER_SOFTWARE'] but I still get in response:
Server: thin 1.3.1 codename Triple Espresso
How to change the value of that header, or remove it completetly from response?
EDIT
Another try:
before do
headers 'Server' => 'ipm'
end
after do
headers 'Server' => 'ipm'
end
But still no changes.
This works here:
require 'sinatra'
get '/' do
[200, {'Server' => 'My Server'}, 'contents']
end
If you want to do it for all requests:
class ChangeServer
def initialize(app)
#app = app
end
def call(env)
res = #app.call(env)
res[1]['Server'] = 'My server'
return res
end
end
And then you use ChangeServer in your app.

email component smtp error cakephp

im getting this error when sending emails with cake's email component
[smtpError] => 535 5.7.1 http://mail.google.com/support/bin/answer.py?answer=14257 r11sm77490vbx.11
any ideas? here's my code...
$this->Email->to = array(' juan <name#gmail.com>');
$this->Email->from = 'name#gmail.com';
$this->Email->subject = 'Welcome to our really cool thing';
$this->Email->template = 'simple_message';
$this->Email->sendAs = 'both';
$this->Email->smtpOptions = array(
'port'=>'465',
'timeout'=>'30',
'auth' => true,
'host' => 'ssl://smtp.gmail.com',
'username'=>'name#gmail.com',
'password'=>'********',
);
You have a space there before your name, which could possibly be sending the wrong data. Have you tried the code without that extra space?
Well, the link in the error message to google's support forums say that the username and password combination are incorrect. I'd recommend that you try logging in to that gmail account with the specified password, just to triple check that you're not mistaken. That happens a lot to me, all the time.
Secondly, are you sure you're supposed to put the #gmail.com in for the username? Maybe it should just be 'name' rather than 'name#gmail.com'.
Apart from that stated by #Travis ... i would also suggest that the from should also be constructed in this format "Name " ... otherwise I don't think the email will go through.

Why does this hash syntax not work in Rails?

session[:user => user, :user_id => [user.id, user.salt]]
For some reason, that never worked for me.
Thoughts on how I can achieve the following code in one line:
session[:user] = user
session[:user_id] = [user.id, user.salt]
Try
session.merge({:user => user, :user_id => [user.id, user.salt]})
I stuck with the original syntax, because I couldn't find an alternative.