我在我的rails应用程序上有两种不同的Devise模型:工作室和音乐家。
我正在尝试使用我的自定义控制器来完成所有工作,因为音乐家“有一个”地址和其他一些东西。我的音乐家模型具有以下设计方法
:database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable,
:confirmable, :lockable
在 devise.rb 我有:
config.allow_unconfirmed_access_for = 2.days
但是我的主要问题是使用方法“after_inactive_sign_up_path_for”,它会发现它永远不会被调用。创建后,我得到以下内容:
ActionView::Missing template (missing template musicians/registrations/create,
musicians/registrations/create, devise/registrations/create, devise/create,
application/create with --bunch of options and places where he did the search--)
但到目前为止我研究了Devise视图,我不需要创建视图(实际上从未需要)...... 顺便说一句,它创建了活动记录,发送电子邮件和所有东西,问题只是最后一部分:(
以下是 routes.rb
的重要部分devise_for :musicians, :controllers => {:registrations => 'musicians/registrations'}
#Here is the route that I want to redirect the user, it works, already tested
match 'logado', to: 'sessions#logado', via: [:get, :post]
这是我的 controllers / musicians / registrations_controller.rb
class Musicians::RegistrationsController < Devise::RegistrationsController
def new
@musician = Musician.new
@adress = @musician.build_adress
@asset = @musician.build_asset
end
def create
@musician = Musician.new(params[:musician])
@adress = @musician.build_endereco(params[:musician][:adress_attributes])
@asset = @musician.build_asset(:photo => params[:musician][:asset])
if @musician.save
flash[:sucess] = "Welcome"
else
render 'new'
end
end
def update
super
end
protected
def after_inactive_sign_up_path_for(resource)
logado_path
end
end
我的观点组织如下:
views
|--musicians
|--registrations
new.html.erb
edit.html.erb
_form.html.erb
|--sessions
new.html.erb
_form.html.erb
index.html.erb
我使用的是Rails 4,Ruby 2和最新的Devise版本,猜测它是3.2.2 - 任何人都可以帮助我吗?
答案 0 :(得分:0)
....
if @musician.save
flash[:sucess] = "Welcome" #<- i think problem here
else
....
在save
之后,您需要重定向到某个路径或渲染某些内容
像这样的东西
...
if @musician.save
flash[:sucess] = "Welcome" #<- here
return redirect_to some_path #<- path to redirect
else