在Rails 4中,Devise::SessionsController#new发生ActionController::UnknownFormat错误。

3

我已经尝试了很长时间并且在谷歌上搜索了相关问题,但是我无法摆脱它。有人能解释一下为什么会发生这种情况以及如何解决吗?

  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)) 当我注册时,Devise会发送确认链接。当我点击链接时,会收到上述错误,并且这是我的网址。
http://localhost/users/sign_in.47

更新1

以下是confirmations_controller.rb的show action。

  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,但这似乎给我带来了麻烦。


你能否在这里更新你的确认控制器的show操作。 - Dipak Gupta
@NitinVerma请查看我的更新问题。 - Prabhakaran
主要问题在于URL末尾的.47,可能是您的用户ID。但需要找出它来自哪里。可能您的确认链接存在问题。您能否告诉我您正在使用的devise gem版本? - Dipak Gupta
哎呀,我在这里做了一项疯狂的工作,看看我的更新问题。 - Prabhakaran
1
好的,请将这行代码 User.where(id: resource.id).update_all(online: true) 更改为 resource.update_attribute(:online, true) - Dipak Gupta
@NitinVerma 真是帮了我省下不少时间!!! - Prabhakaran
2个回答

4
在您的ApplicationController中,如果还没有这一行,请尝试添加以下内容:
respond_to :html, :json

1
主要问题在于URL末尾的.47,可能是您的用户ID。但需要找出它来自哪里。您的确认链接可能存在问题。
根据您更新的问题,请更改after_sign_up_or_sign_in_path_for方法中的以下行。
将此行User.where(id: resource.id).update_all(online: true)更改为resource.update_attribute(:online, true)。

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接