Missing template error in rails

Vito

new.html is a registration form ,which creates tutor account . It involves error handling . _error_messages.html.erb is the file which handles the error ,like should be filling in all text fields . e.g , showing : `

The form contains 3 errors.

    Name can't be blank
    Password confirmation can't be blank
    Password confirmation doesn't match Password

However ,when submits the form without any input in new.html ,it shows the error

Missing template tutors/register, application/register with {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}. Searched in: * "C:/RailsInstaller/Ruby2.1.0/lib/ruby/gems/2.1.0/gems/web-console-2.0.0/lib/action_dispatch/templates" * "D:/Sites/abc/app/views"

new.html.erb

 <% provide(:title, 'Registeration') %>
    <h1>Tutor Registration</h1>
    <div class="row">
      <div class="col-md-6 col-md-offset-3">
        <%= form_for(@tutor) do |f| %>
        <%= render 'shared/error_messages' %>

          <%= f.label :name %>
          <%= f.text_field :name, class: 'form-control' %>

          <%= f.label :email %>
          <%= f.text_field :email, class: 'form-control' %>

          <%= f.label :password %>
          <%= f.password_field :password, class: 'form-control' %>

          <%= f.label :password_confirmation, "Confirm Password" %>
          <%= f.password_field :password_confirmation, class: 'form-control' %>



     <%= f.label :gender %>
                <%= f.select(:gender, ['Male', 'Female'] , class: 'form-control' )%>


          <%= f.label :tutor_education_level %>
                    <%= f.select(:education_level, ['Bachelor', 'Master', 'Doctor'] , class: 'form-control' )%>


          <%= f.label :tutor_institution %>
          <%= f.text_field :institution, class: 'form-control' %>

                <%= f.label :tutorial_experience %>
          <%= f.text_field :experience, class: 'form-control' %>

                <%= f.label :tutor_preferred_district %>
          <%= f.text_field :district, class: 'form-control' %>

          <%= f.label :tutor_preferred_subject %>
          <%= f.text_field :subject, class: 'form-control' %>

                <%= f.label :tutor_required_student_level %>

           <%= f.select(:student_level, ['P1-P3', 'P4-P6', 'S1-S3', 'S4-S6'] , class: 'form-control' )%>


          <%= f.submit "Create tutor's account", class: "btn btn-primary" %>

        <% end %>
      </div>
    </div>

views/shared/_error_messages.html.erb

<% if @tutor.errors.any? %>
  <div id="error_explanation">
    <div class="alert alert-danger">
      The form contains <%= pluralize(@tutor.errors.count, "error") %>.
    </div>
    <ul>
    <% @tutor.errors.full_messages.each do |msg| %>
      <li><%= msg %></li>
    <% end %>
    </ul>
  </div>
<% end %>

Tutor -controller

 class TutorsController < ApplicationController
  before_action :logged_in_tutor, only: [:edit, :update]
  before_action :correct_tutor,   only: [:edit, :update]

  def index
    @tutors = Tutor.all
  end

  def show
    @tutor = Tutor.find(params[:id])
  end

  def new
    @tutor = Tutor.new
  end

  def create
    @tutor = Tutor.new(tutor_params)
    if @tutor.save
      log_in @tutor
      flash[:success] = "Congratulations! Your registration is successful!"
      redirect_to @tutor
    else
      render 'register'
    end
  end

  def edit
    @tutor = Tutor.find(params[:id])
  end

  def update
    if @tutor.update_attributes(tutor_params)
      flash[:success] = "Profile updated successfuly!"
      redirect_to @tutor
    else
      render 'edit'
    end
  end

  # Handle sign-up failure, to redirect the tutor to the registeration form again
  def tutor_params
    params.require(:tutor).permit(:name, :email, :password, :password_confirmation, :address,:gender ,:education_level,:institution,:exprience,:district,:subject,:student_level)
  end

  def logged_in_tutor
    unless logged_in?
      store_location
      flash[:danger] = "Please log in."
      redirect_to login_url
    end
  end

  def correct_tutor
    @tutor = Tutor.find(params[:id])
    redirect_to(root_url) unless current_tutor?(@tutor) 
  end
end
Зелёный

When you submit the form, request sends to the create action:

 def create
    @tutor = Tutor.new(tutor_params)
    if @tutor.save
      # if @tutor valid save it and redirect to show action
      redirect_to @tutor
    else
      # else render the register template(or action)
      render 'register'
    end
  end

In the create action there is a conditional if, in the first case all is good, @tutor has been saved and Rails call redirect to show action, otherwise Rails trying to render register template which is not exists(the errors claims about it). To resolve that issue create register template with desired html code which should run if @tutor isn't saved.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

TOP Ranking

  1. 1

    Failed to listen on localhost:8000 (reason: Cannot assign requested address)

  2. 2

    Loopback Error: connect ECONNREFUSED 127.0.0.1:3306 (MAMP)

  3. 3

    How to import an asset in swift using Bundle.main.path() in a react-native native module

  4. 4

    pump.io port in URL

  5. 5

    Compiler error CS0246 (type or namespace not found) on using Ninject in ASP.NET vNext

  6. 6

    BigQuery - concatenate ignoring NULL

  7. 7

    ngClass error (Can't bind ngClass since it isn't a known property of div) in Angular 11.0.3

  8. 8

    ggplotly no applicable method for 'plotly_build' applied to an object of class "NULL" if statements

  9. 9

    Spring Boot JPA PostgreSQL Web App - Internal Authentication Error

  10. 10

    How to remove the extra space from right in a webview?

  11. 11

    java.lang.NullPointerException: Cannot read the array length because "<local3>" is null

  12. 12

    Jquery different data trapped from direct mousedown event and simulation via $(this).trigger('mousedown');

  13. 13

    flutter: dropdown item programmatically unselect problem

  14. 14

    How to use merge windows unallocated space into Ubuntu using GParted?

  15. 15

    Change dd-mm-yyyy date format of dataframe date column to yyyy-mm-dd

  16. 16

    Nuget add packages gives access denied errors

  17. 17

    Svchost high CPU from Microsoft.BingWeather app errors

  18. 18

    Can't pre-populate phone number and message body in SMS link on iPhones when SMS app is not running in the background

  19. 19

    12.04.3--- Dconf Editor won't show com>canonical>unity option

  20. 20

    Any way to remove trailing whitespace *FOR EDITED* lines in Eclipse [for Java]?

  21. 21

    maven-jaxb2-plugin cannot generate classes due to two declarations cause a collision in ObjectFactory class

HotTag

Archive