从控制器渲染部分:layout => !request.xhr?返回缺少的模板?

时间:2013-07-05 20:53:57

标签: ruby-on-rails-3

我克隆并调整了这个rails app,我在使用ajax请求时渲染部分时出现了一些问题,在日志中我看到有罪行在registrations_controller.rb(设计)

class RegistrationsController < Devise::RegistrationsController

  def create
    build_resource

    if resource.save
      if resource.active_for_authentication?
        sign_in(resource_name, resource)
        (render(:partial => 'thankyou', :layout => false) && return)  if request.xhr?
        respond_with resource, :location => after_sign_up_path_for(resource)
      else
        resource.update_attribute(:encrypted_password, nil) # make sure there is no password
        expire_session_data_after_sign_in!
        (render(:partial => 'thankyou', :layout => false) && return)  if request.xhr?
        respond_with resource, :location => after_inactive_sign_up_path_for(resource)
      end
    else
      clean_up_passwords resource
      render :partial => 'email_capture', :action => :new, :layout => !request.xhr?**
    end
  end

  protected

  def after_inactive_sign_up_path_for(resource)
    '/thankyou.html'
  end

  def after_sign_up_path_for(resource)
    redirect_to root_path
  end

end

返回的错误消息是:

  

ActionView :: MissingTemplate - 缺少部分

     

     

with {:locale =&gt; [:en],:formats =&gt; [:html],:handlers =&gt; [:erb,:builder,   :咖啡,:haml]}。搜索范围:*   “/用户/的Davide /文档/工作现场/导轨-发射前-注册-1点击/应用/意见”   *“/Users/Davide/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/devise_invitable-1.1.8/app/views”   *“/Users/Davide/.rbenv/versions/1.9.3-p194/lib/ruby/gems/1.9.1/gems/devise-2.2.4/app/views”

有趣的是,如果我删除:layout =&gt; != request.xhr?参数部分被找到但页面刷新并丢失所有样式表和其他资产。

任何想法我应该从哪里开始寻找?

谢谢!

1 个答案:

答案 0 :(得分:0)

我还克隆并修改了该项目,并遇到了几乎相同的问题。对我来说,问题会出现在第二次保存错误的电子邮件地址失败后 - 但结果是相同的。

通过使用以下问题/答案中的上下文和信息: form returned from AJAX request is not recognized as 'remote' when submitted

我能够做出改变来解决我的问题。在_email_capture.html.erb中,将:remote => true,添加到simple_form_for行。就我而言,整个修订的行是:

<%= simple_form_for resource, :as => resource_name, :remote => true, :url => registration_path(resource_name) , :html => {:class => 'form-inline'} do |f| %>

希望这也有助于你!