Ruby 如何使用rails版本3.2.19解决MassaSignmentSecurity错误
有谁能帮我用rails版本3.2.19解决以下错误吗?当我向数据库提交值时,这个错误就来了 错误 我的代码片段如下 views/users/new.html.erbRuby 如何使用rails版本3.2.19解决MassaSignmentSecurity错误,ruby,ruby-on-rails-3,Ruby,Ruby On Rails 3,有谁能帮我用rails版本3.2.19解决以下错误吗?当我向数据库提交值时,这个错误就来了 错误 我的代码片段如下 views/users/new.html.erb <center> <h1>Enter your data</h1> <% if @user.errors.any? %> <div id="error_explanation"> <h2><%= pluralize(@u
<center>
<h1>Enter your data</h1>
<% if @user.errors.any? %>
<div id="error_explanation">
<h2><%= pluralize(@user.errors.count, "error") %> prohibited this post from being saved:</h2>
<ul>
<% @user.errors.full_messages.each do |message| %>
<li><%= message %></li>
<% end %>
</ul>
</div>
<% end %>
<div class="form-div">
<%= form_for :user,:url => {:action => 'create'} do |f|%>
<p>
<%= f.label :Name %>
<%= f.text_field :name,placeholder:"Enter your name" %>
</p>
<p>
<%= f.label :Email %>
<%= f.email_field :email,placeholder:"Enter your Email" %>
</p>
<p>
<%= f.label :Password %>
<%= f.password_field :password,placeholder:"Enter your password" %>
</p>
<p>
<%= f.label :password %>
<%= f.password_field :con_password,placeholder:"Enter your password again" %>
</p>
<p>
<%= f.label :content %>
<%= f.text_field :content,placeholder:"Enter your content" %>
</p>
<p>
<%= f.submit "Create User",:class => 'submit' %>
</p>
<% end %>
</div>
</center>
控制器/用户\u controller.rb
class UsersController < ApplicationController
def index
end
def new
@user=User.new
end
def show
end
def create
@user=User.new(params[:user])
if @user.save
flash[:notice]="User has created successfully"
flash[:color]="valid"
redirect_to :action => 'index'
else
flash[:alert]="User could not create"
flash[:color]="invalid"
render :new
end
end
end
model/user.rb
class User < ActiveRecord::Base
attr_accessible :content, :email, :name, :password
EMAIL_REGEX = /\A[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}\z/i
validates :name, :presence => true, :uniqueness => true, :length => { :in => 3..20 }
validates :email, :presence => true, :uniqueness => true, :format => EMAIL_REGEX
validates :password, :confirmation => true
validates_length_of :password, :in => 6..20, :on => :create
end
迁移\20150128062543\u创建\u用户.rb
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :email
t.string :password
t.string :content
t.timestamps
end
end
end
请帮助我解决此问题。您应该将您的字段密码命名为“确认”,而不是“确认”,因为如果您的模型具有validates:password,confirmation:true:
您还必须向模型中可访问的属性添加密码确认 否,在添加行@Marek后再次显示相同的错误。你还有其他解决办法吗?@Subhra\u代理忘记了attr\u。检查我编辑的答案。将所有数据放在适当的位置后,现在它工作正常。
class CreateUsers < ActiveRecord::Migration
def change
create_table :users do |t|
t.string :name
t.string :email
t.string :password
t.string :content
t.timestamps
end
end
end
<%= f.password_field :password_confirmation, placeholder: "Enter your password again" %>