删除空白<%= f.select :challenge_id, options_for_select(@current_user_challenges.collect { |current| [current.full_challenge, current.id] }) %>
选项的最佳做法是什么?
形式
#My Attempts:
@current_user_challenges = current_user.challenges.order(:created_at).where("user_id > 0")
@current_user_challenges = current_user.challenges.order(:created_at).reject!(&:blank?)
@current_user_challenges = current_user.challenges.order(:created_at).reject { |id| id.blank? }
@current_user_challenges = current_user.challenges.order(:created_at).select!{|val| !val.empty?}
challenges_controller
let menuTap = UITapGestureRecognizer(target: self, action: #selector(showMenuPanel(_:)))
menuTap.minimumPressDuration = 0.0
menuTap.numberOfTapsRequired = 2
menuTap.delaysTouchesBegan = true
self.view.isUserInteractionEnabled = true
self.view!.addGestureRecognizer(menuTap)
func showMenuPanel(_ recognizer: UITapGestureRecognizer) {
print("TESTPANEL")
}
答案 0 :(得分:2)
您可以使用present?
检查
@current_user_challenges =
current_user.includes(:challenges).challenges.order(:created_at).select{ |challenge| challenge.full_challenge.present? }
另外,我建议您在模型级别添加presence validation
class Challenge
validates :full_challenge, presence: true
end