【问题标题】:Devise custom controller Missing Template create设计自定义控制器缺少模板创建
【发布时间】:2013-12-22 06:31:27
【问题描述】:

我的 rails 应用上有两个不同的设计模型:工作室和音乐家。

我正在尝试使用我的自定义控制器让一切正常工作,因为音乐家“has_one”地址和其他一些东西。我的 Musicians 模型具有以下设计方法

: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--)

但就我研究设计视图而言,我不需要创建视图(实际上从未需要)... 顺便说一句,它创建活动记录,发送电子邮件和所有东西,问题只是最后一部分:(

这里是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 - 任何人都可以帮助我吗?

【问题讨论】:

    标签: ruby ruby-on-rails-3 devise ruby-on-rails-4 devise-confirmable


    【解决方案1】:
    ....
    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
    

    【讨论】:

      猜你喜欢
      • 2013-12-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多