Forum: Ruby on Rails before_action - performing an action to prevent

4ac3db469730f27f69b0e7897f2d7524?d=identicon&s=25 "Денис Чурбанов" <odmin.odin@gmail.com> (Guest)
on 2013-10-18 17:56
(Received via mailing list)
class WebsocketController < WebsocketRails::BaseController

  private

  def authenticate?
    unless current_user.token == message[:token]
      current_redirect_to 'home/index'
      false # that here we need to do to stop the further execution?
    end
  end

end

class WorldsController < WebsocketController
  before_action :authenticate?

  def index
    current_html_insert 'worlds/index'
  end

end

From the documentation: If you call *render*, *head* or *redirect_to*
from
a *before_action*, the filter chain will be halted, but I have a
different
situation:
current_redirect_to and current_html_insert - are methods of controlling
the
behavior of the client through websockets,
they do not call methods *render*, *head* or *redirect_to.
*Please tell me how can I fix this problem.
52f3528c40e9cf28ad0900886eecb128?d=identicon&s=25 Jordon Bedwell (Guest)
on 2013-10-18 22:09
(Received via mailing list)
On Fri, Oct 18, 2013 at 7:02 AM, Денис Чурбанов <odmin.odin@gmail.com>
wrote:
> From the documentation: If you call render, head or redirect_to from a
> before_action, the filter chain will be halted, but I have a different
> situation:
> current_redirect_to and current_html_insert - are methods of controlling the
> behavior of the client through websockets,
> they do not call methods render, head or redirect_to.
> Please tell me how can I fix this problem.

Render nothing (literally.)

class WebsocketController < WebsocketRails::BaseController
  private

  def authenticate?
    unless current_user.token == message[:token]
      current_redirect_to 'home/index'
      render :nothing => true, :status => 301
    end
  end
end
4ac3db469730f27f69b0e7897f2d7524?d=identicon&s=25 "Денис Чурбанов" <odmin.odin@gmail.com> (Guest)
on 2013-10-19 07:08
(Received via mailing list)
Thank you, this is what you need!

, 19  2013 ., 0:07:23 UTC+4  Jordon Bedwell
:
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.