I'm having some trouble trying to submit an AJAX request to a separate controller in my view.
My form for the AJAX request looks like this:
I've also tried sites_search_results_index_path
which my routes file says is the proper route.
View:
<div class="pull-left col-md-5">
<%= form_tag url: sites_search_results, remote: true do %>
<div class="input-group">
<%= content_tag :span, class: "input-group-btn" do %>
<%= button_tag type: "button", class: "btn btn-default dropdown-toggle", data: { toggle: "dropdown" } do %>
<%= content_tag :span, "", class: "caret" %>
<% end %>
<%= content_tag :ul, class: "dropdown-menu" do %>
<li class="btn btn-default">Domain</li>
<li class="btn btn-default">CLW</li>
<% end %>
<% end %>
<%= hidden_field_tag "search_by", "Domain" %>
<%= content_tag :span, class: "input-group-addon", id: "search_view" do %>
Filter
<% end %>
<%= text_field_tag "search_for", "", :class => "form-control" %>
<%= content_tag :span, class: "input-group-btn" do %>
<%= button_tag "Search", class: "btn btn-default" %>
<% end %>
</div>
<% end %>
</div>
Controller:
class SitesSearchResultsController < ApplicationController
def index
field = "Domain"
@results = Domain.where()
respond_to do |format|
format.js # do ajax action
end
end
end
Routes:
resource :sites_search_results do
post 'index'
end
# also tried with no result:
#post "sites_search_results/index"
rake routes
has:
sites_search_results POST /sites_search_results/index(.:format) sites_search_results#index
POST /sites_search_results(.:format) sites_search_results#create
The result of this is:
undefined local variable or method `sites_search_results'
Any idea what would cause this? I've seen other people have this problem but I have the root path set up already to go to the status page. And I don't see anything that would be attempting to post to root. Let me know if anything else is needed to help. And thanks in advance!