Saturday, 15 August 2015

rails search form 'no such column: name' error -


I am trying to apply a simple search box in my index view, but he gave me this error: < / P> <<">" Ticket "from where (name '% s%')

I can" TICK "Find out why this is and I How do I correct it? Below is my MVC

See

  

listing ticket & Lt;% = form_tag tickets_path ,: method = & gt; 'get'%> & lt; p & gt; & lt;% = text_field_tag: search, parameter [: search]% & Gt; & lt;% = submit_tag 'search'%> & lt; / p & gt; & lt;% end% & gt; & lt; table & gt; & lt; tr & gt; & Lt; / tr & gt; & lt;% @ tickets.each do | tickets & gt; & lt; tr & gt; & lt; td & gt; & lt;% = ticket.caller_name% & gt; <% = ticket.called_date%> <% = ticket.problem % & Gt; & lt; / td & gt; ... & lt;% end% & gt; & lt; / table & gt;

model

  class tickets & lt; ActiveRecord :: Base attr_accessible: called_date ,: caller_name, problem: has_many: logs,: dependent = & gt; delete DEF self.search (search) if search (all :: conditions => Other end and end   

controller

  Class Ticket Controller & LT; ApplicationController def index @tickets = Ticket.all @tickets = tickets. Search (params [: search]) response_to do | Format | Format.html # index.html.erb format.json {render json: @tickets} and end    

You are trying to query the column name on your ticket table. So replace it with the column in your column, caller_name . Change the following line:

  find (all:, conditions => [['name'? ','% # {Search}% "])   
  find (all:, conditions => [like 'caller_name', '% # {search}% "])    

No comments:

Post a Comment