Hi I have searched many sites and videos on rails casts but cannot find an answer to this, I have a urls controller and url model. in the controller I have this
def search
@search_term = params[:q]
st = "%#{params[:q]}%"
@url = Url.where("email ILIKE ? or custref ILIKE ? or order_number ILIKE ? or url4 ILIKE ? or trader_code ILIKE ? or trader_name ILIKE ?", st, st, st, st, st, st).order("date DESC").page(params[:page]).per_page(25)
respond_to do |format|
format.html
format.json {render json: @urls}
end
end
And in the model is just this
class Url < ActiveRecord::Base
attr_accessible :order_number, :url1, :url2, :url3, :url4, :url5, :email, :custref, :date, :trader_code, :trader_name
def self.import(file)
CSV.foreach(file.path, headers: true) do |row|
Url.create! row.to_hash
end
end
belongs_to :user
end
I am then using a partial to render the form_tag for the search box.
<%= form_tag("/search", :method => "get") do %>
<%= label_tag(:q, "") %>
<%= text_field_tag(:q) %>
<%= submit_tag "Search" %>
<% end %>
my problem is that I have no idea how to validate this form_tag. I need to validate that there is a valid and full email address entered into the search and I need to validate that there is exactly 8 characters entered to search for the order_number. The rest of the validations I can figure out after but these two are the most important. I have watched videos on railscast for active_attr but it doesn't work for me. Has anybody done this before that would be able to help me out?
Thanks