【问题标题】:ActionController::UnknownFormat in Devise::SessionsController#new in rails 4在 Rails 4 中的 Devise::SessionsController#new 中的 ActionController::UnknownFormat
【发布时间】:2014-08-25 14:10:32
【问题描述】:

我尝试了很长时间,并在谷歌上搜索了我无法摆脱的问题。任何人都可以解释为什么会发生这种情况以及如何解决它。

  def new
    self.resource = resource_class.new(sign_in_params)
    clean_up_passwords(resource)
    respond_with(resource, serialize_options(resource))
  end

错误在下一行 respond_with(resource, serialize_options(resource))

当我注册设计时会发送一个确认链接。当我单击出现上述错误的链接时,这是我的网址

http://localhost/users/sign_in.47

更新 1

这是我对confirms_controller.rb 的展示动作

  def show
    self.resource = resource_class.confirm_by_token(params[:confirmation_token])
    yield resource if block_given?

    if resource.errors.empty?
      set_flash_message(:notice, :confirmed) if is_flashing_format?
      respond_with_navigational(resource){ redirect_to after_confirmation_path_for(resource_name, resource) }
    else
      respond_with_navigational(resource.errors, status: :unprocessable_entity){ render :new }
    end
  end

def after_sign_up_or_sign_in_path_for resource
      User.where(id: resource.id).update_all(online: true)
      dashboard_path
    end

一旦用户登录,我需要将用户更新为在线,所以我使用了 resource.id,这似乎让我很麻烦

【问题讨论】:

  • 您能否在此处更新确认控制器的显示操作。
  • @NitinVerma 检查我更新的问题
  • 是的,主要问题是在 url 的末尾有.47。这可能是您的用户 ID。但需要找到它的来源。可能是您的确认链接有问题。您能否也告诉我您使用的是哪个 gem 版本的设计。
  • 是的,我知道我在这里做了一项疯狂的工作,请参阅我更新的问题
  • 好的,把User.where(id: resource.id).update_all(online: true)这一行改成resource.update_attribute(:online, true)

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


【解决方案1】:

在您的 ApplicationController 中尝试添加此行(如果它不存在):

respond_to :html, :json

【讨论】:

    【解决方案2】:

    主要问题在于网址末尾的.47。这可能是您的用户 ID。但需要找到它的来源。可能是您的确认链接有问题。

    根据您更新的问题,请在after_sign_up_or_sign_in_path_for 方法中更改以下行。

    将此行 User.where(id: resource.id).update_all(online: true) 更改为 resource.update_attribute(:online, true)

    【讨论】:

      猜你喜欢
      • 2013-10-12
      • 1970-01-01
      • 2022-08-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-07-15
      • 1970-01-01
      相关资源
      最近更新 更多