【问题标题】:Rails error on respond_to [closed]response_to上的Rails错误[关闭]
【发布时间】:2013-04-04 16:19:29
【问题描述】:

我已经为学习 Rails 创建了一个简单的用户身份验证:

class UsersController < ApplicationController
   def new
     @user = User.new
   end

   def create
     respond_to do |format|
        if @user.save
           format.hmtl {redirect_to root_url}
        else
           format.hmtl {render 'new'}
        end
    end
 end

如果我创建一个没有块 respond_to 和 format.html 的新用户,一切正常(在数据库中我有创建的用户并且页面被重定向)。 使用此代码,创建了用户,但我有以下错误(并且我没有重定向):

Completed 500 Internal Server Error in 218ms

NameError (uninitialized constant Mime::HMTL):
   app/controllers/users_controller.rb:16:in `block in create'
   app/controllers/users_controller.rb:14:in `create'

P.S:我想要 respond_to 和 format,因为在我想要添加 format.json 方法之后

谢谢

【问题讨论】:

    标签: ruby-on-rails ruby-on-rails-3 authentication respond-to


    【解决方案1】:

    您有一个错字 - 将 format.hmtl 更改为 format.html

    【讨论】:

    • 对不起,我不明白我必须改变什么……你能解释一下吗?
    • 在您的代码中,您将字母htmlhmtl 混淆了——当然,这不是您要查找的mime 类型。除非您使用 HyperMarkup 文本语言...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-30
    • 1970-01-01
    • 2018-06-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多