У меня есть 2 пользовательских модели в моем приложении: «Участник» и «Участник». Я пытаюсь разрешить им включать пользовательское сообщение, когда они приглашают других участников/участников через Devise Invitable. Однако я не могу заставить его работать.Невозможно заставить пользователей создавать настраиваемое сообщение с изобретательностью invitable
Я следую за этим official tutorial, поэтому я сделал следующие изменения, чтобы переопределить Invise Invitable Controller, но при использовании pry кажется, что этот пользовательский контроллер остается нетронутым при отправке приглашения. Что я делаю неправильно:
Контроллеры/Участники/invitations_controller.rb
class Participants::InvitationsController < Devise::InvitationsController
before_action :update_sanitized_params, only: :update
def create
binding.pry
@from = params[:from]
@subject = params[:invite_subject]
@content = params[:invite_content]
@participant = Participant.invite!(params[:user], current_member) do |u| #XXX Check if :user should be changed
u.skip_invitation = true
end
ParticipantInvitationNotificationMailer.invite_message(@participant, @from, @subject, @content).deliver if @participant.errors.empty?
@participant.invitation_sent_at = Time.now.utC# mark invitation as delivered
if @participant.errors.empty?
flash[:notice] = "successfully sent invite to #{@participant.email}"
respond_with @participant, :location => root_path
else
render :new
end
end
def update
respond_to do |format|
format.js do
invitation_token = Devise.token_generator.digest(resource_class, :invitation_token, update_resource_params[:invitation_token])
self.resource = resource_class.where(invitation_token: invitation_token).first
resource.skip_password = true
resource.update_attributes update_resource_params.except(:invitation_token)
end
format.html do
super
end
end
end
protected
def update_sanitized_params
devise_parameter_sanitizer.permit(:accept_invitation, keys: [:password, :password_confirmation, :invitation_token, :username])
end
end
конфигурации/routes.rb
Rails.application.routes.draw do
devise_for :members, controllers: { invitations: "members/invitations" }
devise_for :participants, controllers: { invitations: "participants/invitations" }
end
модели/participant.rb
class Participant < ApplicationRecord
attr_reader :raw_invitation_token
end
отправителей/notification_mailer.rb
class NotificationMailer < ApplicationMailer
def invite_message(user, from, subject, content)
@user = user
@token = user.raw_invitation_token
invitation_link = accept_user_invitation_url(:invitation_token => @token)
mail(:from => from, :bcc => from, :to => @user.email, :subject => subject) do |format|
content = content.gsub '{{first_name}}', user.first_name
content = content.gsub '{{last_name}}', user.last_name
content = content.gsub '{{full_name}}', user.full_name
content = content.gsub('{{invitation_link}}', invitation_link)
format.text do
render :text => content
end
end
end
end
Если я отправить приглашение: с Participant.invite!({:email => '[email protected]'}, Member.first)
приглашение посылается через почтовую программу по умолчанию, как показано на консоли, но не в моей новой почтовой программе. Зачем?
Rendering /Users/andres/.rvm/gems/[email protected]/gems/devise_invitable-1.7.1/app/views/devise/mailer/invitation_instructions.html.erb
Rendered /Users/andres/.rvm/gems/[email protected]/gems/devise_invitable-1.7.1/app/views/devise/mailer/invitation_instructions.html.erb (0.6ms)
Rendering /Users/andres/.rvm/gems/[email protected]/gems/devise_invitable-1.7.1/app/views/devise/mailer/invitation_instructions.text.erb
Rendered /Users/andres/.rvm/gems/[email protected]/gems/devise_invitable-1.7.1/app/views/devise/mailer/invitation_instructions.text.erb (0.8ms)