vendredi 27 février 2015

Why do I get the error: TypeError in UsersController#create can't convert String into Hash

I am trying to implement a email functionality so that when someone registers they recieve an email. I am following this guide: http://ift.tt/KXJcBq


But I get the error:



TypeError in UsersController#create
can't convert String into Hash


application_mailer.rb:



class ApplicationMailer < ActionMailer::Base
default "from@example.com"
layout 'mailer'
end


user_mailer.rb:



class UserMailer < ApplicationMailer
default from: 'notifications@example.com'

def welcome_email(user)
@user = user
@url = 'http://localhost:3000/users/login'
mail(to: @user.email, subject: 'Welcome to My Awesome Site')
end
end


views/user_mailer/welcome_email.html.erb:



<!DOCTYPE html>
<html>
<head>
<meta content='text/html; charset=UTF-8' http-equiv='Content-Type' />
</head>
<body>
<h1>Welcome to example.com, <%= @user.name %></h1>
<p>
You have successfully signed up to example.com,
your username is: <%= @user.login %>.<br>
</p>
<p>
To login to the site, just follow this link: <%= @url %>.
</p>
<p>Thanks for joining and have a great day!</p>
</body>
</html>


views/user_mailer/welcome_email.txt.erb



Welcome to example.com, <%= @user.name %>
===============================================

You have successfully signed up to example.com,
your username is: <%= @user.login %>.

To login to the site, just follow this link: <%= @url %>.

Thanks for joining and have a great day!


And the create method in users_controller:



def create
@user = User.new(user_params)
if @user.save
# login is achieved by saving a user's 'id' in a session variable,
# accessible to all pages
UserMailer.welcome_email(@user).deliver_later
session[:user_id] = @user.id
redirect_to films_path
else
render action: "new"
end
end


Can someone please help.


Aucun commentaire:

Enregistrer un commentaire