Forum: Ruby on Rails How to abort program flow after a redirect?

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
9e7c9c07e64a6b7b075097831c360d53?d=identicon&s=25 Bill Katz (Guest)
on 2005-12-30 15:11
(Received via mailing list)
I'm developing an authorization plug-in which adds a permit keyword, so
you
can do things like:

class FooController < ApplicationController
  permit "member"

  def edit
    permit "owner of :document", :document => Document.find(params[:id])
    # stuff to edit..
  end
end

I've got it mostly working, but if the permit in #edit fails, a
redirection
within permit won't short-circuit the statements after the permit. It
can
work by using a block, as in:

permit "admin or owner of :document" do
  # stuff to edit
end

or a simple expression like:

if permit? "admin"
  # stuff to edit
end

But I'd like a failed permit to act like a "return" at the level of
#edit,
so any statements downstream aren't executed. Any ideas?

Thanks, Bill
67b6389be42524fbd776e44fd35c3d7e?d=identicon&s=25 Peter Donald (Guest)
on 2005-12-31 01:56
(Received via mailing list)
Hi,

How about

return unless permit "owner of :document", :document =>
Document.find(params[:id])

--
Cheers,

Peter Donald

Blog: http://www.RealityForge.org
9e7c9c07e64a6b7b075097831c360d53?d=identicon&s=25 Bill Katz (Guest)
on 2005-12-31 06:26
(Received via mailing list)
I guess that's the simplest solution if I can't figure out a way to
bundle
the return into the permit declaration. Was trying to see how far the
metaprogramming could be taken.
This topic is locked and can not be replied to.