# Rendering now!

**URL:** <https://www.ruby-forum.com/t/rendering-now/108121>\
**Category:** Rails\
**Created:** [June 29, 2007, 6:24am UTC](https://www.ruby-forum.com/t/rendering-now/108121 "2007-06-29T06:24:27Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [June 29, 2007, 6:24am UTC](https://www.ruby-forum.com/t/rendering-now/108121/1 "2007-06-29T06:24:27Z")

</div>

anyone got a slicker way to do this?

[http://drawohara.tumblr.com/post/4517961](http://drawohara.tumblr.com/post/4517961)

thanks.

## -a

we can deny everything, except that we have the possibility of being  
better. simply reflect on that.  
h.h. the 14th dalai lama

---

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [June 29, 2007, 6:31am UTC](https://www.ruby-forum.com/t/rendering-now/108121/2 "2007-06-29T06:31:28Z")

</div>

On Thu, Jun 28, 2007 at 10:23:09PM -0600, ara.t.howard wrote:

> anyone got a slicker way to do this?
> 
> [http://drawohara.tumblr.com/post/4517961](http://drawohara.tumblr.com/post/4517961)

You could have login! return false if it renders and then do something  
like:

def post\_comment  
return unless login!

or

def post\_comment  
login! || return

Not very pretty and kind of a little too implicit versus the throw/catch  
approach but it’s less complex than the throw/catch for the case you  
show in  
your post.

## marcel

Marcel Molina Jr. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)

---

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [June 29, 2007, 6:48am UTC](https://www.ruby-forum.com/t/rendering-now/108121/3 "2007-06-29T06:48:29Z")

</div>

On 6/29/07, ara.t.howard [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> –  
> we can deny everything, except that we have the possibility of being  
> better. simply reflect on that.  
> h.h. the 14th dalai lama

Ara,

Is there a reason why you couldn’t put this into a before filter and  
avoid  
the problem altogether.

This is the way it’s done in the restful\_authentication plugin

before\_filter :login\_required, :(except | only) =\> [actions]

This way the action never gets called if the login\_required method  
returns  
false. Then the login\_required method can call a render or redirect  
etc.

Sorry If I’m missing something…  
Cheers  
Daniel

---

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [June 29, 2007, 7:02am UTC](https://www.ruby-forum.com/t/rendering-now/108121/4 "2007-06-29T07:02:30Z")

</div>

On Jun 28, 2007, at 10:29 PM, Marcel Molina Jr. wrote:

> return unless login!
> 
> or
> 
> def post\_comment  
> login! || return

right. i’m way too stupid the remember that every time though 😉

> Not very pretty and kind of a little too implicit versus the throw/  
> catch  
> approach but it’s less complex than the throw/catch for the case  
> you show in  
> your post.

completely agree. the issue, i guess, is that there is no way to  
pull out any logic that does a render under some condition and place  
it outside the controller. so every controller then has to  
duplication the code. of course there are filters, but that’s not  
well suited to something you only do some of the time.

in this case though your solution or a filter is far easier.

kind regards.

## -a

we can deny everything, except that we have the possibility of being  
better. simply reflect on that.  
h.h. the 14th dalai lama

---

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [June 29, 2007, 7:11am UTC](https://www.ruby-forum.com/t/rendering-now/108121/5 "2007-06-29T07:11:31Z")

</div>

On Jun 28, 2007, at 10:47 PM, Daniel N wrote:

> Daniel

that certainly seems to be the obvious answer here - i should have  
picked a better example for that post! 😉

so yeah, that’s fine here - i was more generally wondering about  
being able to factor out and arbitrary peice of logic that might  
cause something to be rendered and the login seemed like the obvious  
example.

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

---

<div class="post-metadata">

**Author:** ![ara.t.howard](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/a/a8b319/32.png) [@ara.t.howard](https://www.ruby-forum.com/u/ara.t.howard)\
**Post date:** [June 30, 2007, 5:45pm UTC](https://www.ruby-forum.com/t/rendering-now/108121/6 "2007-06-30T17:45:39Z")

</div>

On Jun 28, 2007, at 10:47 PM, Daniel N wrote:

> Daniel

this summarizes i think

[http://drawohara.tumblr.com/post/4627267](http://drawohara.tumblr.com/post/4627267)

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
