My application has deals and orders. I’m processing the orders manually by clicking a link my my admin area when viewing the deals.
views/access/deals/index.html.erb
<%= link_to "Process Orders", process_orders_access_deal_path(deal) %>
In my /controllers/access/deals_controller.rb, I have the following method.
def process_orders
@deal = Deal.find(params[:id])
@orders = @deal.orders.where("state" == ?, "pending")
@orders.each do |order|
order.purchase
end
end
My purchase method is not in my deals model, it’s in my orders model because I set it up there before needing to make changes where orders would not be processed immediately.
Purchase method in orders controller.
def purchase
response = Order.gateway.purchase(order_amount, billing_id, options)
end
Is it possible to access the purchase method in my order.rb model from my /controllers/access/deals_controller.rb and if so how?
Have you tried calling it?
Controllers and models aren’t linked by some inexplicable magic. You are able to reference any class (i.e. model) from any other class you want (i.e. controller). There is no restriction.