Hi, I’m learning Rails and saw a strang thing for me.
Yesterday, I was told by my friend that there is a method named
‘redirect_to’. He showed how to use the method like this:
redirect_to :back
So, I wanted to find an Api document of the method on the internet,
and tried to know which class or module owns it at first…
$ rails console
irb(main)001:0> controller = ActionController::Base.new
=> #<ActionController::Base:0x00000004561ab8 @_routes=nil,
@_action_has_layout=true, @_headers={“Content-Type”=>“text/html”},
@_status=200, @_request=nil, @_response=nil>
irb(main):003:0> controller.method(:redirect_to).owner
=> ActionController::Instrumentation
So I searched ‘redirect_to’ at http://api.rubyonrails.org/ by using
keyword “ActionController::Instrumentation”.
But the document says almost nothing but just the method signeture and
its source code.
redirect_to(*args)
File actionpack/lib/action_controller/metal/instrumentation.rb, line
58
def redirect_to(*args)
ActiveSupport::Notifications.instrument(“redirect_to.action_controller”)
do |payload|
result = super
payload[:status] = response.status
payload[:location] = response.location
result
end
end
I tried the same search by Google, then I found
the same name method in another module and realized that it was what my
friend told me, because it explained the meaning of ‘redirect_to :back’.
http://api.rubyonrails.org/classes/ActionController/Redirecting.html#method-i-redirect_to
But why did I fail to search such a simple thing like this?
Something must have been wrong. I’m very confused.
Was the way of checking class(or method) through irb wrong?
Please give me some advice.
Regards.