Problem with url_for and named routes in ActionMailer View: "Controller and action required"

I try to provide a confirmation link in my user welcome email and I get the following Rails error:

Need controller and action!

This bothers this line:

<p>Please take a moment to activate your account by going to: 
<%= link_to confirm_user_url(:id => @user.confirmation_code) %>.</p>

In my environment development.rb, I have the following line:

config.action_mailer.default_url_options = {
  :host => "localhost", :port => 3000
}

No problem with the variable @user. I tested email with things like @user.usernameand @user.confirmation_code. I'm having trouble with url_forand are called routes like confirm_user_url.

When I check my routes with rake routes, it appears confirm_user, so this is not a problem with the specified route that does not exist.

I can’t figure it out. What gives?

+3
2

URL- - , , , macek

<p>Please take a moment to activate your account by going to: 
<%= auto_link confirm_user_url(:id => @user.confirmation_code) %>.</p>

auto_link , URL- , . , api . .

+3

ActionMailer Rails, . , .

. - SampleMailer:

class SampleMailer < ActionMailer::Base

  def confirmation_mail(user)
    subject    'Confirmation'
    recipients user.email
    from       'sample@example.com'
    sent_on    Time.now
    body       :greeting => 'Sample Greeting', :email => user.email,
               :confirm_user_url => confirm_user_url(:id=>@user.confirmation_code)
  end
end

:

<%= link_to "Confirmation link", @confirm_user_url %>

api "ActionMailer" Agile Web Development Rails, 3- ., 25.

+9

Source: https://habr.com/ru/post/1742189/


All Articles