我知道有一些关于此问题的帖子,但从我看到的内容来看,它们相当老旧,可能已经过时了。我正在使用 devise 和 devise_invitable。其背后的想法是允许管理员和教师...
我知道有一些关于此问题的帖子,但是从我看到的内容来看,它们已经很旧了,可能已经过时了。
我正在使用 devise 和 devise_invitable。其背后的想法是允许管理员和教师邀请新用户(学生或教师)。但是当我发送邀请时,出现以下错误:
Missing host to link to! Please provide the :host parameter, set default_url_options[:host], or set :only_path to true
Extracted source (around line #4):
2
3
4
5
6
7
@virtual_path = "devise/mailer/invitation_instructions";; @output_buffer.safe_append='<p>'.freeze; @output_buffer.append=( t("devise.mailer.invitation_instructions.hello", email: @resource.email) ); @output_buffer.safe_append='</p>
<p>'.freeze; @output_buffer.append=( t("devise.mailer.invitation_instructions.someone_invited_you", url: root_url) ); @output_buffer.safe_append='</p>
<p>'.freeze; @output_buffer.append=( link_to t("devise.mailer.invitation_instructions.accept"), accept_invitation_url(@resource, invitation_token: @token) ); @output_buffer.safe_append='</p>
我尝试了很多不同的东西,现在我的代码是这样的:
邀请控制器
class Users::InvitationsController < Devise::InvitationsController
def create
super do |resource|
if resource.persisted? && resource.role == "aluno"
AlunoProfile.create(
user: resource,
morada: params[:user][:morada],
birthdate: params[:user][:birthdate],
nif: params[:user][:nif],
numero_utente: params[:user][:numero_utente],
cartao_cidadao: params[:user][:cartao_cidadao],
validity: params[:user][:validity],
contacto: params[:user][:contacto],
encarregado_educação: params[:user][:encarregado_educação],
grau_parentesco: params[:user][:grau_parentesco],
contacto_emergencia: params[:user][:contacto_emergencia],
aulas: params[:user][:aulas],
horario_preferencial: params[:user][:horario_preferencial],
recolha_dados: params[:user][:recolha_dados],
fotografias_captadas: params[:user][:fotografias_captadas]
)
end
end
end
private
def set_params
params.require(:user).permit(:email, :first_name, :last_name)
end
end
Invitation_instructions 视图
<p><%= t("devise.mailer.invitation_instructions.hello", email: @resource.email) %></p>
<p><%= t("devise.mailer.invitation_instructions.someone_invited_you", url: root_url) %></p>
<p><%= link_to t("devise.mailer.invitation_instructions.accept"), accept_invitation_url(@resource, invitation_token: @token) %></p>
<% if @resource.invitation_due_at %>
<p><%= t("devise.mailer.invitation_instructions.accept_until", due_date: l(@resource.invitation_due_at, format: :'devise.mailer.invitation_instructions.accept_until_format')) %></p>
<% end %>
<p><%= t("devise.mailer.invitation_instructions.ignore") %></p>
我的路线
Rails.application.routes.draw do
# devise_for :users
devise_for :users, RegistrationsController: { registrations: 'registrations'}
root to: "pages#home"
get "about", to: "pages#about"
get "school", to: "pages#school"
get "today", to: "aulas#today"
get "clientes", to: "user_aulas#clientes"
resources :aluno_profiles
resources :aulas do
resources :bookings, only: %i[create destroy]
end
# Define your application routes per the DSL in https://guides.rubyonrails.org/routing.html
# Reveal health status on /up that returns 200 if the app boots with no exceptions, otherwise 500.
# Can be used by load balancers and uptime monitors to verify that the app is live.
get "up" => "rails/health#show", as: :rails_health_check
# Defines the root path route ("/")
# root "posts#index"
end```
使用 Devise_invitable 发送邀请时出错
下载声明:
本站所有软件和资料均为软件作者提供或网友推荐发布而来,仅供学习和研究使用,不得用于任何商业用途。如本站不慎侵犯你的版权请联系我,我将及时处理,并撤下相关内容!