导轨中缺少模板错误

维托

new.html是一个注册表格,用于创建导师帐户。它涉及错误处理。_error_messages.html.erb是处理错误的文件,就像应该填写所有文本字段。例如,显示:`

The form contains 3 errors.

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

但是,当在没有任何输入的情况下提交表单时new.html,它会显示错误

缺少模板导师/注册,应用/注册 {:locale=>[:en], :formats=>[:html], :variants=>[], :handlers=>[:erb, :builder, :raw, :ruby, :coffee, :jbuilder]}。搜索: * "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 /意见”

新的.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>

意见/共享/_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 %>

导师-控制器

 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
绿色的

当您提交表单时,请求发送到create操作:

 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

create动作中有一个条件if,在第一种情况下一切都很好,@tutor已经保存并且 Rails 调用重定向来显示动作,否则 Rails 试图render注册不存在的模板(错误声称)。要解决该问题,请register使用所需的 html 代码创建模板,如果@tutor未保存,则应运行该模板

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

导轨5未定义模板错误

来自分类Dev

Rails缺少模板错误

来自分类Dev

Rails 4缺少模板错误

来自分类Dev

Rails 错误缺少模板 (haml)

来自分类Dev

导轨中的示波器分辨率错误

来自分类Dev

导轨中的延迟作业导致闪存错误

来自分类Dev

模板丢失-导轨

来自分类Dev

如何处理布线错误和通用导轨中的错误

来自分类Dev

Omniauth:“缺少模板错误”-Ruby on Rails

来自分类Dev

即使在路由中添加,也缺少模板错误

来自分类Dev

提交表单后出现“缺少模板”错误

来自分类Dev

Rails:更新模型属性。错误缺少模板

来自分类Dev

缺少必需的键:[:id]导轨

来自分类Dev

在我的路线上遇到一个奇怪的错误,“缺少必需的钥匙”导轨4

来自分类Dev

当获得缺少图像的ImageField的宽度时,防止Django模板中的错误

来自分类Dev

当获得缺少图像的ImageField的宽度时,防止Django模板中的错误

来自分类Dev

PG pg_ext导轨中的加载错误

来自分类Dev

错误“宝石安装导轨”

来自分类Dev

参数缺失错误(导轨)

来自分类Dev

导轨负载错误

来自分类Dev

在Angular中包含指令-缺少模板吗?

来自分类Dev

播放模板中的“缺少参数类型”

来自分类Dev

如何修复Rails 3中缺少的模板?

来自分类Dev

解决Java中缺少模板的问题

来自分类Dev

VS2015中缺少“ VSPackage”模板

来自分类Dev

播放模板中的“缺少参数类型”

来自分类Dev

phpDocumentor 生成的文档模板中缺少图标

来自分类Dev

Cakephp中缺少插件错误

来自分类Dev

在Android中缺少资源错误