lundi 10 octobre 2016

Adding multi table/field search to legacy rails

I'm trying to fix an old bug in my companies simple call logging system. Ruby version 1.9.2 and Rails version 3.1.3

Now to start on what the problem is, I am having issues trying to update our search page to not only search the 'details' in the 'calls' table, but to also search the 'content' in the 'resolutions' table through one text entry in a search form.

The relevant info from both SQL tables:

Calls id - Integer details - Text

Resolutions id - Integer content - Text call_id - Integer

Here is the current code in place.

_search.html.erb

<center>
<%= form_for @search, :url => { :action => "search" } do |f| %>
<div id="accordion_search">
    <h3><a href="#">Search</a></h3>
    <div>
<p>
    <%= f.label :id, "Call ID:" %>
    <%= f.text_field :id_equals, "size" => 3 %>

    <%= f.label :username, "Logged by:" %>
    <%= select :search,:username_equals,@user.collect{|p| [p.username]},:prompt => true%>

    <%= f.label :platform, "Platform:" %>
    <%= select :search,:platform_equals,@platform.collect{|p| [p.name]},:prompt => true%>

    <%= f.label :location, "Location:" %>
    <%= select :search,:location_equals,@location.collect{|p| [p.name]},:prompt => true%>
<p>
    <%= f.label :severity, "Severity:" %>
    <%= select :search,:severity_equals,@severity.collect{|p| [p.name]},:prompt => true%>

    <%= f.label :openstate, "Open:" %>
    <%= select( :search, :openstate_equals, { "" => "", "Yes" => "false", "No" => "true"})%>

    <%= f.label :vpn, "VPN:" %>
    <%= select( :search, :vpn_equals, { "" => "", "Yes" => "true", "No" => "false"}) %>

    <%= f.label :details, "Details:" %>
    <%= f.text_field :details_contains, "size" => 20 %>
<p>
<b>(Date Range)</b>
<p>
    <%= f.label :created_at, "From:" %>
    <%= f.text_field :created_at_greater_than_or_equal_to, :id=>"date_from", :size => 15 %>

    <%= f.label :created_at, "To:" %>
    <%= f.text_field :created_at_less_than_or_equal_to, :id=>"date_to", :size => 15 %>
</p>

<p>
    <%= f.submit "Search" %> <b><%= @calls_count %></b> Calls Found
</p>
   <%= primary_reload_button_link_to 'Reset Search' ,search_calls_path %> <br />
</center>
<% end %>
</div>
</div>

calls_controller.rb

  def search
    @search = Call.recent.search(params[:search])
    @search_params = params[:search]
    @calls = @search.page(params[:page]).per(9)
    @calls_count = @search.count
    @platform = Platform.find(:all)
    @location = Location.find(:all)
    @severity = Severity.find(:all)
    @user = User.find(:all)
end

Aucun commentaire:

Enregistrer un commentaire