Code sample: class SomeController < ApplicationController before_filter do |c| add_crumb "Blah", "/blah" #breadcrumbs plugin redirect_to :controller => "foo", :action => "bar" unless c.send (:has_package?) end # Rest of the controller... private def has_package? # A bunch of logic work to check to make sure # somebody's session contains certain variables # returns ONLY true or false. end The problem I'm having is that I'm getting "undefined method" errors for redirect_to. This confuses me since SomeController inherits from ApplicationController which inherits from ActionController::Base. Any idea what's causing this problem? I'm thinking this is a scope issue somehow, but I'm not sure why it's failing like this. Thanks.
on 2009-04-24 03:45
on 2009-04-24 03:51
One thing I forgot to mention. I've tweaked it so that I CAN get it to work by calling the redirect_to method while inside has_package? - so basically it looks like this: def has_package? # if conditions redirect_to :controller => "foo", :action => "bar" # else redirect_to :controller => "foo", :action => "bar" # end end So before_filter is calling this method which CAN access redirect_to as inherited from ActionController::Base. I'm just confused as to why I have some obvious inheritance issues here.
on 2009-04-24 09:48
On Apr 24, 2:50 am, Phoenix Rising <PolarisRis...@gmail.com> wrote: > end > > So before_filter is calling this method which CAN access redirect_to > as inherited from ActionController::Base. I'm just confused as to why > I have some obvious inheritance issues here. > with a before_filter using the block syntax self is the SomeController class itself, but redirect_to is an instance method. Much as you have to call your has_package method on the controller instance that is yielded to the block you must also call redirect_to on that object. Fred
on 2009-04-24 11:47
So then would the syntax be: c.redirect_to ... ? Thanks Fred - for the record, you're the man ;-) On Apr 24, 1:47 am, Frederick Cheung <frederick.che...@gmail.com>
on 2009-04-24 12:06
On Apr 24, 10:46 am, Phoenix Rising <PolarisRis...@gmail.com> wrote: > So then would the syntax be: > > c.redirect_to ... > Yup (unless the method was protected/private in which case you could use send, but i don;t think it is) Fred