对于最后的日子,我想申请一个测试邀请系统。我遵循了第124课的铁路课。我为我的用户定制了它。未定义的方法`signup_path'的邀请(仍不能发送测试邀请)
我的routes.rb
resources :invitations, only: [:new, :create]
match '/signup/:invitation_token', to: 'users#new'
邀请型号:
class Invitation < ActiveRecord::Base
attr_accessible :new, :recipient_email, :user_id, :sent_at, :token
belongs_to :user
has_one :recipient, :class_name => 'User'
validates_presence_of :recipient_email
validate :recipient_is_not_registered
validate :user_has_invitations, :if => :user
before_create :generate_token
before_create :decrement_user_count, :if => :user
private
def recipient_is_not_registered
errors.add :recipient_email, 'zaten siteye üye' if User.find_by_email(recipient_email)
end
def user_has_invitations
unless user.invitation_limit > 0
errors.add_to_base 'Siteye davetiyeniz kalmamıştır.'
end
end
def generate_token
self.token = Digest::SHA1.hexdigest([Time.now, rand].join)
end
def decrement_user_count
user.decrement! :invitation_limit
end
end
Invitations_controller:
class InvitationsController < ApplicationController
def new
@invitation = Invitation.new
end
def create
@invitation = Invitation.new(params[:invitation])
@invitation.user = current_user
if @invitation.save
if signed_in?
Mailer.deliver_invitation(@invitation, signup_path(@invitation.token))
flash[:notice] = "Teşekkürler,davetiniz gönderildi."
redirect_to root_path
else
flash[:notice] = "Teşekkürler,sizi almaya hazır olduğumuzda bildireceğiz."
redirect_to root_path
end
else
render :action => 'new'
end
end
end
。 这是我mailer.rb:
def invitation(invitation, signup_url)
subject 'Siteye Davet'
recipients invitation.recipient_email
from 'fo[email protected]'
body :invitation => invitation, :signup_url => signup_path
invitation.update_attribute(:sent_at, Time.now)
end
当我发出了邀请,我的日志文件显示:
INSERT INTO "invitations" ("created_at", "recipient_email", "sent_at", "token", "updated_at", "user_id") VALUES (?, ?, ?, ?, ?, ?) [["created_at", Wed, 04 Jul 2012 21:55:13 UTC +00:00], ["recipient_email", "[email protected]"], ["sent_at", nil], ["token", "c29e2dcc22c033a1e975f5755795db9f2a8fd5c2"], ["updated_at", Wed, 04 Jul 2012 21:55:13 UTC +00:00], ["user_id", 1]]
(131.3ms) commit transaction
Completed 500 Internal Server Error in 208ms
NoMethodError (undefined method `signup_path' for #<InvitationsController:0x000000044ef508>):
我能理解我必须改变SIGNUP_URL的。但我无法找到正确的方法。如何修复邀请创建操作?
我没有看到signup_path实际定义在任何地方,你是否错过了一些你可以添加到问题的来源? – MBHNYC