The Artima Developer Community
Sponsored Link

Ruby Buzz Forum
What's New in Edge Rails: Filters get Tweaked

0 replies on 1 page.

Welcome Guest
  Sign In

Go back to the topic listing  Back to Topic List Click to reply to this topic  Reply to this Topic Click to search messages in this forum  Search Forum Click for a threaded view of the topic  Threaded View   
Previous Topic   Next Topic
Flat View: This topic has 0 replies on 1 page
rwdaigle

Posts: 312
Nickname: rwdaigle
Registered: Feb, 2003

Ryan is a passionate ruby developer with a strong Java background.
What's New in Edge Rails: Filters get Tweaked Posted: Oct 22, 2007 11:27 AM
Reply to this message Reply

This post originated from an RSS feed registered with Ruby Buzz by rwdaigle.
Original Post: What's New in Edge Rails: Filters get Tweaked
Feed Title: Ryan's Scraps
Feed URL: http://feeds.feedburner.com/RyansScraps
Feed Description: Ryan Daigle's various technically inclined rants along w/ the "What's new in Edge Rails" series.
Latest Ruby Buzz Posts
Latest Ruby Buzz Posts by rwdaigle
Latest Posts From Ryan's Scraps

Advertisement

Controller filters just got a little update that may mess with your flow. As of now, returning false no longer halts the execution of the action chain. Instead, rendering or redirecting is what automatically stops the action chain.

If you think about it, it makes sense that rendering or redirecting within a filter signals the abortion of normal action execution since you can only render/redirect once per call and doing so reasonably indicates that no more processing is required.

So where before you might have had a filter such as:

1
2
3
4
5
6
def must_be_logged_in
  if(not user_logged_in?)
    redirect_to login_url
    return false
  end
end

You can now let the act of rendering or redirecting imply completion instead of returning false:

1
2
3
def must_be_logged_in
  redirect_to login_url if not user_logged_in?
end

At first blush I thought this might mess up existing filters, but a quick review of mine indicated that whenever I return false I’ve already rendered or redirected. Not sure if this holds true for everybody or not…

tags: ruby, rubyonrails

Read: What's New in Edge Rails: Filters get Tweaked

Topic: Troubleshooting DB2 on Rails Previous Topic   Next Topic Topic: Hey, flexmock and unit_record, play nice!

Sponsored Links



Google
  Web Artima.com   

Copyright © 1996-2019 Artima, Inc. All Rights Reserved. - Privacy Policy - Terms of Use