[Boulder Ruby Group] rendering now!
Bruce Williams
bruce at codefluency.com
Fri Jun 29 02:13:52 EDT 2007
Ara,
The filter needs to return false to stop the action dispatch.
Here's a working example (just played with it):
--snip--
class FoosController < ApplicationController
before_filter :authenticate
def index
# won't get here
end
#######
private
#######
def can_find_account # stub, use some method that's useful
return false
end
def authenticate
unless can_find_account
render :template => 'shared/access_denied'
return false
end
end
end
--snip--
I generally like rendering directly vs redirection in these cases.
Cheers,
Bruce
---
Bruce Williams
http://codefluency.com
On 6/28/07, ara.t.howard <ara.t.howard at gmail.com> wrote:
>
>
> On Jun 28, 2007, at 11:32 PM, Brian Rose wrote:
>
> I might be misunderstanding, but if the problem is a double render, just
> return the render:
>
> before_filter :authenticate
>
>
> def authenticate
> self.current_user ||= (session[:user] && User.find_by_id(session[:user]))
> || false
> return redirect_to(login_path) unless current_user
> end
>
>
>
>
>
> that's precisely how i ended up double rendering while testing my code ;-)
>
>
> def action_that_needs_authentication
> authenticate
> render
> end
>
>
>
>
> cheers.
>
>
> -a
> --
> we can deny everything, except that we have the possibility of being
> better. simply reflect on that.
> h.h. the 14th dalai lama
>
>
>
>
>
> _______________________________________________
> Bdrg-members mailing list
> Bdrg-members at rubyforge.org
> http://rubyforge.org/mailman<http://rubyforge.org/mailman/listinfo/bdrg-members>/listinfo/bdrg-members<http://rubyforge.org/mailman/listinfo/bdrg-members>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://rubyforge.org/pipermail/bdrg-members/attachments/20070629/58d1d1d6/attachment-0001.html
More information about the Bdrg-members
mailing list