我有一个应用程序发送包含注册链接的邀请电子邮件。但是注册链接给出了错误。如果注册链接不存在,电子邮件将发送。
NoMethodError in Invitations#create
undefined method `accept_referral_invitation_url' for #(#(Class:0xadd8c90):0xb5d868cc)
错误发生在这一行
= accept_referral_invitation_url(@invitation.invite_token)
邀请控制器
class InvitationsController < ApplicationController
def new
@invitation = Invitation.new
end
def create
@invitation = current_user.invitations.new(params[:invitation])
if @invitation.valid?
@invitation.save
redirect_to root_url, :notice => "Invitation sent!"
UserMailer.invitation(@invitation).deliver
else
render "new", :notice => "Somehting went wrong!"
end
end
def accept_referral
@invitation = Invitation.find_by_invite_token(params[:invite_token])
@invitation.accepted_at = Time.zone.now
@invitation.save!
redirect_to root_url, :notice => "Success!"
end
end
用户邮件
class UserMailer < ActionMailer::Base
def invitation(invitation)
@invitation = invitation
mail(:to => invitation.email, :subject => "You're invited", :from => 'alain@lootfly.com')
end
end
邀请.html.haml(被发送的消息)
You have been cordially invited to join beta.
Click this link to sign up!
= accept_referral_invitation_url(@invitation.invite_token)
= accept_referral_invitation_url(invite_token: @invitation.invite_token)
# I TRIED BOTH OF THOSE LINKS^^^^ TO NO AVAIL!!!!!!!
邀请函模型
create_table "invitations", :force => true do |t|
t.integer "user_id"
t.text "email"
t.text "invite_token"
end
编辑:耙路线
invitations GET /invitations(.:format) invitations#index
POST /invitations(.:format) invitations#create
new_invitation GET /invitations/new(.:format) invitations#new
edit_invitation GET /invitations/:id/edit(.:format) invitations#edit
invitation GET /invitations/:id(.:format) invitations#show
PUT /invitations/:id(.:format) invitations#update
DELETE /invitations/:id(.:format) invitations#destroy