respond_to 和 format.json 没有找到偏音

respond_to with format.json doesn't find partials

我正在覆盖设计会话控制器,并在尝试设置特定格式时 Rails 说没有部分,但事实并非如此 当我试图将它插入 respond_to

class SessionsController < Devise::SessionsController
  def new
    self.resource = resource_class.new(sign_in_params)
    clean_up_passwords(resource)
    yield resource if block_given?
    respond_to do |format|
      format.html
      format.json {render(json: { sign_in: render_to_string(partial: 'static_pages/home')})}
    end

  end

错误是:

缺少部分 static_pages/_home 与 {:locale=>[:en], :formats=>[:json], :variants=>[], :handlers=>[:raw , :erb, :html, :builder, :ruby, :coffee, :jbuilder]}。搜索范围:* "D:/project_traveldiary/app/views" * "D:/RailsInstaller/Ruby2.3.3/lib/ruby/gems/2.3.0/gems/devise-4.6.2/app/views"

它似乎在搜索 json 部分,因此请尝试明确指定部分的格式:

render_to_string(partial: 'static_pages/home', formats: :html)