私はまだレールで学習曲線にあり、コーナーに戻ったようです。
シナリオ:
人の詳細(id、first_name、last_name)を含む配列があり、配列の内容がビューに表示されます(テーブルとしてフォーマットされます)。
そのビューのコントローラーには、配列にフィルターを適用するメソッドがあります-その出力を制限します。
コントローラ
#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
意見
#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>
ルートファイル
#/config/routes.rb
MyApplication::Application.routes.draw do
resources :persons do
collection do
get :filter_person
end
end
end
ビューのハイパーリンクを使用して、フィルターコントローラーメソッドをトリガーして配列をフィルター処理し、このフィルターを配置してビューを更新できるようにしたいと思います。私は何が欠けていますか?