ruby on rails - If search on model has no hits, invoke javascript file -


i make search on model:

def self.search(search) if search     where('bezeichnung like?', "%#{search}%") else    end end 

what change, when search has no hits fires javascript file in icd/index.js.erb

index.js.erb:

$('#chapter_list').html("<%= escape_javascript(render(:partial => 'icd1')) %>"); 

how can this?

presumably class method (self.search) on model. since controllers return responses from, you'd need have controller respond javascript code.

something like:

def index   results = model.search(params[:search])   respond_to |format|     if results       format.html { render 'index.html.erb' }     else       format.js { render 'index.js.erb' }     end   end end 

Comments

Popular posts from this blog

c# - Send Image in Json : 400 Bad request -

javascript - addthis share facebook and google+ url -

ios - Show keyboard with UITextField in the input accessory view -