i have create a simple user authentication for learning 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

If i create a new user without the block respond_to and format.html all works fine (in the db i have the created user and the page is redirected). With this code, the user is created but i have the following error (and i don't have the redirection):

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: i want the respond_to and format because after i want add the format.json method

Thanks

有帮助吗?

解决方案

You have a typo - change format.hmtl to format.html

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top