Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/81.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Html 处理注册失败失败_Html_Ruby On Rails_Ruby - Fatal编程技术网

Html 处理注册失败失败

Html 处理注册失败失败,html,ruby-on-rails,ruby,Html,Ruby On Rails,Ruby,我以前做过一个名为address的属性。但是我没有在报名表上用它。当我在注册表单中输入所有文本字段时,它会闪烁错误 表单包含1个错误 地址不能为空 我还应该去别的地方看看吗 控制器 def new @tutor = Tutor.new end def create @tutor = Tutor.new(tutor_params) if @tutor.save log_in @tutor

我以前做过一个名为
address
的属性。但是我没有在报名表上用它。当我在注册表单中输入所有文本字段时,它会闪烁错误

表单包含1个错误

地址不能为空

我还应该去别的地方看看吗

控制器

 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 'tutors/new'
        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,:gender 
          ,:education_level,:institution,:exprience,:district,:subject,:student_level)
      end
注册页面

     <%= 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 %>
tutor.rb(更新2)
`class Tutor
还要确保您的导师模型中的地址有效。

更改

validates :address, presence: true, length: {maximum: 100}

在model tutor.rb中

在创建导师时,您正在验证模型中是否存在地址字段,但未传递地址参数

如果要从数据库中删除现有地址字段, 在你的终点站,做什么

rails g migration remove_address_from_tutors
在新创建的迁移文件中添加以下代码

class RemoveAddressFromTutors < ActiveRecord::Migration
  def change
    remove_column :tutors, :address
  end
end
class RemoveAddressFromTutors

然后在您的终端中执行
rake db:migrate
是否可以共享tutor模型当您渲染到新操作时,它会覆盖@tutor object.@Sajin我应该显示什么文件请发布您的
tutor.rb
模型。请在app/models中共享tutor.rb文件,因为这个
地址
属性现在已无用,如何从模型中删除此属性您必须创建一个迁移以从数据库中删除此字段。我是否可以直接删除
创建
迁移文件或删除
架构上的
地址
行。rb
否这不是正确的方法。
正确的方法
表示可以,但不建议这样做?
def create
        @tutor = Tutor.new(tutor_params)
        if @tutor.save
          log_in @tutor
          flash[:success] = "Congratulations! Your registration is successful!"
          redirect_to @tutor
        else
          flash[:tutor] = @tutor
          redirect_to new_tutor_path
        end
      end
validates :address, presence: true, length: {maximum: 100}
validates :address, length: {maximum: 100}
rails g migration remove_address_from_tutors
class RemoveAddressFromTutors < ActiveRecord::Migration
  def change
    remove_column :tutors, :address
  end
end