2011-12-10 2 views
0

私のTokeninputオートコンプリートフィールドには、と:websiteの両方の返された列が定義された:storeメソッドになったときに返すようにしようとしています。スコープは両方の列を認識しませんか?

class BusinessStore < ActiveRecord::Base 
    scope :search_by_store, lambda { |q| 
     (q ? where(["address LIKE ? or website LIKE ? like ?", '%'+ q + '%', '%'+ q + '%','%'+ q + '%' ]) : {})} 

    def store 
     if self.online_store 
      "#{business_name} - #{website}" 
     else 
      "#{business_name} - #{address}" 
     end 
    end 
end 

class BusinessStoresController < ApplicationController 

    def index 
    @business_stores = BusinessStore.all 
    @business_stores = BusinessStore.search_by_store(params[:q]) 

    respond_to do |format| 
     format.html # index.html.erb 
     format.xml { render :xml => @business_stores } 
     format.json { render :json => @business_stores.collect{|b|{:id => b.id, :name => b.store } } } 
    end 
    end 
end 

私のJSONのページ:http://localhost:3000/business_stores.jsonが正しく、すべての結果を示しているが、トークンフィールドは、:address結果ではなく、ウェブサイトのものを示しています。これをどうやって解決するのですか?

答えて

1

はこれを試してみてください:

(q ? where(["address LIKE ? OR website LIKE ?", "%#{q}%", "%#{q}%" ]) : {})} 
+0

はあなたの先生ありがとうございました!感謝します。 – LearningRoR

関連する問題