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
Post a Comment