I'm still on the learning curve with rails, and seem to have backed myself into a corner.
Scenario:
There is an Array containing people details (id, first_name, last_name), and the Array contents are displayed in a View (formatted as a table).
There is a method in the Controller for that View which applies a filter to the array - limiting its output.
Controller
#person_controller.rb
require 'module_file'
class PersonController < ApplicationController
include ModuleFile
helper_method :build_list
def index
end
def filter_person
@filter_criteria = lambda { |person| person.id.nil? }
redirect_to persons_path
end
end
View
#index.html.erb
<%= link_to "Filter Report", :controller => :person, :action => :filter_person %>
<table>
<% ModuleFile.build_list.individuals.find_all(&@filter_criteria).each do |person| %>
<tr>
<td><%= person.id %></td>
<td><%= person.first_name %></td>
<td><%= person.last_name %></td>
</tr>
<% end %>
</table>
Routes File
#/config/routes.rb
MyApplication::Application.routes.draw do
resources :persons do
collection do
get :filter_person
end
end
end
I would like to be able to use a hyperlink on a View to trigger the filtering controller method to filter the Array, and then refresh the View with this filter in place. What am I missing?