我在注册表单上遇到问题.它是使用SimpleForm创建的,使用Devise进行身份验证.提交表单时,如果电子邮件或密码为空,则会显示两次错误.在用户模型中,存在对名字,姓氏,配置文件名称,密码和电子邮件的存在验证.这些重复错误仅显示在空白电子邮件和密码字段中.任何其他空白字段都会这样说一次.
例:
#错误禁止此用户被保存:
- 电子邮件不能为空
- 电子邮件不能为空
- 密码不能为空
- 密码不能为空
user.rb:
class User < ActiveRecord::Base
devise :database_authenticatable, :registerable,
:recoverable, :rememberable, :trackable, :validatable
attr_accessible :email, :password, :password_confirmation, :remember_me, :first_name, :last_name, :profile_name
validates :first_name, :last_name, :email, :profile_name, :password, presence: true
validates :profile_name, uniqueness: true,
format: {
with: /^[a-zA-Z0-9_-]+$/
}
has_many :posts
def full_name
first_name + " " + last_name
end
end
Run Code Online (Sandbox Code Playgroud)
注册/ new.html.erb:
<%= simple_form_for(resource, :as => resource_name, :url => registration_path(resource_name)) do |f| %>
<%= devise_error_messages! %>
<div class="formGroupLeft">
<%= f.input :first_name, :input_html => { …Run Code Online (Sandbox Code Playgroud) 我正在尝试使用simple_form构建月份的下拉选择输入.但是,我无法确定从哪里开始.目前,它是一个文本输入区:
<%= f.input :start_month %>
Run Code Online (Sandbox Code Playgroud)
我需要知道要通过哪些参数才能成为所有12个月的下拉列表.它对于几个月返回一个整数值并不重要,但如果我稍后使用它进行排序,它将是理想的.
我仍然是rails的初学者,可以真正使用这个的帮助.我可以提供任何必要的额外信息.
编辑:
我希望下拉列表显示月份名称,而不仅仅是数字.
我有一个表单,我需要用户选择(使用单选按钮)一个选项,它将确定它下面的下一个表单字段.在这种情况下,他们的帖子可以是帖子或帖子的修订版.因此,选择"发布"将显示标题字段(以命名帖子),选择"修订"将显示可供选择的现有帖子的选择列表(标题将被继承).
_form.html.erb
<!--Form inputs-->
<%= f.collection_radio_buttons :is_revision, [[false, 'Post'] ,[true, 'Revision']], :first, :last %>
<%= f.input :revision_id, collection: @originals, :input_html => {:id => 'revision'} %>
<%= f.input :title, :input_html => { :maxlength => '50', :placeholder => 'Title', :id => 'title'} %>
<!--Javascript-->
<script type="text/javascript">
$('input[name="post[is_revision]"]').on("change", function(){
if ( $("#post_is_revision_true").attr("checked")){
$("#title").hide();
$("#revision").show();
}
if ( $("#post_is_revision_false").attr("checked")){
$("#revision").hide();
$("#title").show();
}
});
</script>
Run Code Online (Sandbox Code Playgroud)
我应该提一下,当隐藏和显示一个字段时这很好用,但是当选择另一个单选按钮时没有任何变化.我觉得逻辑是正确的(虽然我不是最强的JS)但我似乎无法得到这个.