0

I have 2 controllers (booking and taxi). I am going to call a method of taxi in create method of booking.

so i saw this, and used this line

class BookingsController < ApplicationController
      def create
        redirect_to url_for(:controller => :taxis, :action => :compute) and return
    end
end

i add and return because i faced with erorr

AbstractController::DoubleRenderError

and compute method is a simple puts

def compute  
   puts "Address is @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@"     
end

the problem is, when i run it, i face with this message

Redirected to http://agile-system-lashkarara.c9users.io:8081/compute

but it puts nothing in console

Community
  • 1
  • 1
Sal-laS
  • 11,016
  • 25
  • 99
  • 169
  • 1
    What are you trying to achieve? Because the 'and return' is not necesarry if you want to redirect_to somewhere in your create method. – bo-oz Nov 23 '15 at 07:06
  • I am expecting to run **compute** method – Sal-laS Nov 23 '15 at 07:07
  • And if you want to do something with a Taxi in the BookingsController, you should probably create a method in the Taxi model, so you can call it directly. If you explain the required functionality I could point you in the right direction. – bo-oz Nov 23 '15 at 07:08
  • It's ok, if i can have the compute in my model. could you please wirte an answer – Sal-laS Nov 23 '15 at 07:15

1 Answers1

0

Move compute to the Taxi model like this:

#model/taxi.rb
#please note that this is a class method and not an instance method!
def self.compute

  puts "Address is @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@        "

end

Then you can call Taxi.compute, but this is probably not exactly what you are looking for, since you will probably need to call the method for a specific Taxi, then you don't need the self. part and you need to call the method on a ActiveRecord object of a Taxi.

bo-oz
  • 2,842
  • 2
  • 24
  • 44