20

Currently working on a project, and have encountered a problem that I have never come across before. Currently doing a login sign up page that ask the user to sign up. I had a undefined method `name'error before, and then realised that the method is not called name it was called full_name. I have gone through all the folders to ensure that any method or attribute is not called 'name' and renamed it to 'full_name. Having refreshed the browser I recieve the following error which I haven't seen before. Can some please explain what this error is and how possibly I may go about resolving it.

Template is missing

Missing template users/create with {:handlers=>[:erb, :rjs, :builder, :rhtml, :rxml], :formats=>[:html], :locale=>[:en, :en]} in view paths "C:/Users/patterd/Documents/Project/app/views"

Nanne
  • 64,065
  • 16
  • 119
  • 163
Deej
  • 5,334
  • 12
  • 44
  • 68

5 Answers5

44

This error happens if you don't redirect in the create method of your controller.

Are you redirecting in the create method in the controller or rendering the new form, in case of error?

Without the redirection in the create method in the controller, you need to make a new file called create.html.erb. Usually, after successful creation, you redirect to some other page like shown below

def create
  # some object you want to create
  # if the object.save is fine
  #   redirect_to object
  # else
  #   render new with the errors
  # end
end
Rápli András
  • 3,869
  • 1
  • 35
  • 55
felix
  • 11,304
  • 13
  • 69
  • 95
  • I do have a user_Controller, and does contain a create method. Which follows 'code'def create @user = User.new(params[:user]) if @user.save # Handle a successful save. else @title = "Sign up" render 'new' end end – Deej Jun 27 '11 at 15:24
  • 3
    OK.after the save, redirect_to some page, for example the redirect :action => :show, so that it goes to one of the pages that you have with the .html.erb extension. usually it ll be the index.html.erb(redirect_to :action => :index) or the show.html.erb(redirect_to :action => :show) – felix Jun 27 '11 at 15:30
  • Oh okay got you. I get why I am recieving this error. Many thanks. – Deej Jun 27 '11 at 15:36
23

In my case I had to process and render no view.

def return_payment
  # do lots of stuff

  head :ok
end
Eduardo Xavier
  • 1,520
  • 21
  • 29
2

I had the same problem and the reason was that I left accidentally other empty 'create' method :)

Artur79
  • 12,705
  • 1
  • 22
  • 22
2

Generally missing template error occurs -when you don't have view file of that method of controller, or -if a method is just for calculation that does not have any view file, then you must have to render/redirect the method.

If you do not render or redirect the method, it will search for the view page of current method name (in your case it will search for create.html.erb).So, you have to render/redirect the method.

Kishan Ku. Patel
  • 311
  • 1
  • 2
  • 10
0

I had the same problem and just added the redirect_to and it worked!

def update
    @visitor = Visitor.find(params[:id])
    if @visitor.update_attributes(visitor_params)
       flash[:notice] = "Update ok!"
       redirect_to root_path #just added this line and it worked!
    else
       render 'edit'
    end
end