Rails Runtime Error in Controller#Index - Unsupported: Symbol -


i've implemented couple of different search forms in app trying achieve 1 specific action (input object id , go straight show page instance), , got close on 1 until ran unsupported: symbol runtime error cards#index.

here search form (i dropped layouts/application.html.erb:

<%= form_tag(cards_path, :method => "get") %>   <div class="input-append">     <%= text_field_tag :search, params[:search], class: "span2", placeholder: "search cards" %>     <button class="btn" type="submit"><i class="icon-search"></i></button>   </div> <% end %> 

and here cards_controller.rb index action:

  def index     if params[:search]       @cards = card.search(params[:search]).order("created_at desc")     else       @cards = card.order("created_at desc")     end   end    def show   end    private    def set_card     @card = card.find(params[:id])   end    def card_params     params.require(:card).permit(:title, :description)   end 

and model card.rb

class card < activerecord::base    validates :title, presence: true, uniqueness: true   validates :description, presence: true    def self.search(query)     where(:id, query)   end end 

i using where("title ?", "%#{query}%") model, read crafting sql queries way security risk , looking exact matches.

so preventing view recognizing id parameter passed search?

there's nothing wrong view - problem search method,

where(:id, query) 

which isn't valid use of where.

it should be

where(id: query) 

or, more old school:

where("id = ?", query ) 

Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -