I have a transactions controller and view. When I click to link "Transactions", I show all transactions.
How to add a before display transactions such as enter start and end dates?
答案 0 :(得分:0)
What you need is probably the ransack
gem.
You can add a custom filtering mechanism in your controller like this:
def index
@q = Transaction.ransack(params[:q])
@transactions = @q.result(distinct: true)
end
and using in the view a simple for like this:
<%= search_form_for @q do |f| %>
<%= f.label :start_date %>
<%= f.search_field :created_at_gteq %>
<%= f.label :end_date %>
<%= f.search_field :created_at_lteq %>
<%= f.submit %>
<% end %>
And this will let you filter the Transaction
data using the created_at
param as a filter. Modify the form accordingly if you need to filter using another Date
/DateTime
param from the model.