user2184718
user2184718

Reputation: 715

Want to have a partial update with ajax

I have a form:

<% form_tag({:controller => "/faq", :action => 'search_ajax'}, :update => "help_results", remote: true) do %>

that is going to the search_ajax action which is supposed to update the help_results div. That action is supposed to render a partial at the end, but I for sure am having syntax issues:

def search_ajax
@categories = HelpCategory.find(:all)

if params[:query].not_blank? && params[:query] != "Search for help about..."
  @query = params[:query]
  @terms = params[:query].split.map {|t| "%#{t.downcase}%" }

  options = {
      :allow_partial_match => true,
      :order => 'fulltext_match_score DESC',
  }
  @results = SearchableText.search_model(HelpItem, @query, options).uniq
  @results = {"Search Results" => @results} if !@results.blank?
  @complicated_query = HelpItem.is_complicated_query?(@query)
  @search_included = true
else
  @results = HelpItem.all.group_by {|item| item.category.name rescue "Misc"}
  @search_included = false
end

render :partial => "results"
respond_to do |format|
  format.js do
    render :partial => 'results'
  end
  format.html do
    render :partial => 'results'
  end
end

end

Some of the respond_to area is commented out. I am getting the error message:

ActionController::DoubleRenderError in FaqController#search_ajax

I know that if I add the remote => true helper into my form that the controller action needs to respond to js. I'm pretty sure this is a syntax error. The respond_to also comes at the end of my controller action.

Upvotes: 0

Views: 45

Answers (1)

j-dexx
j-dexx

Reputation: 10416

Remove the

render :partial => "results"

Above the respond_to block

Upvotes: 1

Related Questions