i would be able to ransack search on a dynamic route path, and the exemples that i have is using a collection on fixed path like this:
collection do
post :search, to: 'exemple#index'
end
so in a Order shop cart exemple like this:
model:
class Order < ActiveRecord::Base
STATUSES = %w(paid sent)
end
controller:
def sent
order = Order.find(params[:id])
@q = Order.where('status = ?', params[:status] || Order.statuses[0]).ransack(params[:q])
@orders = @q.result(distinct: true).paginate(page: params[:page], per_page: 5)
if order
order.status = Order.statuses[1]
order.save
redirect_to "#{sold_orders_path}?status=#{Order.statuses[0]}",
flash: { success: 'State changed' }
end
end
view url: orders/sold?status=paid
i would like to know if is possible to use ransack to make this kind of search or i have to scope this out on the model?
thank's
Aucun commentaire:
Enregistrer un commentaire