Note that there are some explanatory texts on larger screens.

plurals
  1. POWhy am I getting an an undefined method error when I try to add email confirmations in my Rails 4 app?
    text
    copied!<p>I'm a newbie at Rails and I was hoping somebody could help me solve this little problem. I keep on getting an <code>ActionView::Template::Error</code> which says <code>undefined method 'verify_email_users_url' for #&lt;#&lt;Class:0x68d5730&gt;:0x6ac35c0&gt;</code> when I try to implement email confirmations into my Rails 4 app.</p> <p>This is the relevant code for the feature:</p> <p>app/controllers/users_controller.rb</p> <pre><code> def create @user = User.new(user_params) if @user.save UserMailer.registration_confirmation(@user).deliver redirect_to root_url, notice: "A confirmation email has been sent to your inbox" elsif signed_in? redirect_to root_url else render 'new' end end def verify_email @user = User.find_by_email_token(params[:email_token]) @user.email_confirmation_token = true @user.save redirect_to @user, notice: "Your email has been verified!" end </code></pre> <p>app/models/user.rb</p> <pre><code>class User &lt; ActiveRecord::Base before_create :create_email_token def User.new_remember_token SecureRandom.urlsafe_base64 end def User.encrypt(token) Digest::SHA1.hexdigest(token.to_s) end private def create_email_token self.email_token = User.encrypt(User.new_remember_token) end end </code></pre> <p>app/views/user_mailer/registration_confirmation.text.erb</p> <pre><code>To confirm your email, click the URL below. &lt;%= verify_email_users_url(email_token: @user.email_token) %&gt; </code></pre> <p>config/routes.rb</p> <pre><code>SampleApp::Application.routes.draw do resources :users do member do get :following, :followers (this line refers to some other methods) get :verify_email end end end </code></pre> <p>app/mailers/user_mailer.rb</p> <pre><code>class UserMailer &lt; ActionMailer::Base default from: "money@example.com def registration_confirmation(user) @user = user mail to: @user.email, subject: "Please confirm your email" end end </code></pre> <p>Here is the relevant test that is failing. How do I get this test to pass?</p> <p>spec/mailers/user_mailer_spec.rb</p> <pre><code>require "spec_helper" describe UserMailer do let(:user) {FactoryGirl.create(:user, email_token: "fj4543")} let(:mail) {UserMailer.registration_confirmation(user)} it "should send an email confirming a user's email" do mail.subject.should eq("Please confirm your email") mail.to.should eq([user.email]) mail.from.should eq(["money@example.com"]) mail.body.encoded.should match(verify_email_users_path(email_token: user.email_token)) end end </code></pre> <p>If anyone could tell me where I'm going wrong that would be great. If you need any more information to understand what is going on here, please do no hesitate to ask.</p> <p>Thank you.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload