简体   繁体   中英

Ruby on Rails- Making input required for a form

I am trying to make this input in my search required to start a search. I tried :validate if there is input but that didn't work. Any suggestions?

<%= text_field_tag "location", params[:location], :placeholder => 'City, zipcode, or address' %>

In whatever model the location belongs to, try adding this syntax:

class whatever < ActiveRecord::Base    
  validates :location, presence: true
end

make sure that location is part of attar_accessible in your model.

change the syntax

<%= text_field_tag "location", "#{params[:location]}", :placeholder => 'City, zipcode, or address' {:required => true} %>

and add this to your model

validates :location, presence: true 

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM