我的网站上的登录表单中有一个:remember_me
复选框。为复选框编写以下代码后,它显示为文本输入,而不是复选框。我该如何将其变成一个复选框?
<%= simple_form_for :session, url: login_path do |f| %>
<%= f.input :email, placeholder: "Email Address", class: "form-control" %>
<%= f.input :password, placeholder: "Password", class: "form-control" %>
<%= f.input :remember_me, inline_label: "Remember me", class: "checkbox inline" %>
<%= f.button :submit, "log in", class: "btn btn-success btn-block login-bar" %>
<% end %>
在我的User.rb
文件中,我有以下方法:
def remember
self.remember_token = User.new_token
update_attribute(:remember_digest, User.digest(remember_token))
end
def forget
update_attribute(:remember_digest, nil)
end
答案 0 :(得分:2)
simple_form提供<div class="form-group container">
<label for="">Repetir?</label>
<div class="form-check">
<input type="checkbox" class="form-check-input" id="segunda">
<label class="form-check-label">Segunda</label>
<m></m>
<input type="checkbox" class="form-check-input" id="segunda">
<label class="form-check-label">Terça</label>
<m></m>
<input type="checkbox" class="form-check-input" id="segunda">
<label class="form-check-label">Quarta</label>
<m></m>
<input type="checkbox" class="form-check-input" id="segunda">
<label class="form-check-label">Quinta</label>
<m></m>
<input type="checkbox" class="form-check-input" id="segunda">
<label class="form-check-label">Sexta</label>
<m></m>
<input type="checkbox" class="form-check-input" id="segunda">
<label class="form-check-label">Sábado</label>
<m></m>
<input type="checkbox" class="form-check-input" id="segunda">
<label class="form-check-label">Domingo</label>
<m></m>
</div>
</div>
助手(source)
所以你必须这样做:
boolean
(假设<%= f.input :remember_me, as: :boolean, inline_label: "Remember me", class: "checkbox inline" %>
返回布尔属性)