Yehuda Katz
(ph) 718.877.1325

2011/12/19 Nicolás Sanguinetti <[email protected]>

> On Mon, Dec 19, 2011 at 11:56 PM, Steve Klabnik <[email protected]>
> wrote:
> > throw/catch for flow control is bad.
>
> Indeed it is. It's the one thing in Sinatra I always disliked.
>
> If I had to choose, I would go down the path of render/redirect
> returning a response, so you would do something like `return render
> :new` or `return redirect_to @object`.
>
> This has the added bonus that it's compatible with 99.9% of the uses
> of render and redirect (being the last line of an action/conditional)
> thanks to the implicit returns.
>
> def create
>  @obj = Obj.new(…)
>
>  if @obj.save
>    redirect_to @obj, notice: …
>  else
>    render :new
>  end
> end
>
> That still works as expected.
>
> But if you did:
>
> def create
>  render :foo
>  render :bar
> end
>
> You get the response generated by "render :bar" and the other one is
> ignored. Because it's just an object returned, instead of some black
> magic depending on class state.
>
> That said, this would require quite the refactoring in ActionPack.
>

It actually wouldn't require major refactoring. The work we did in 3.0 made
this possible. Unfortunately, it breaks some common scenarios:

def create
  render :foo
  Rails.logger.info "hi"
end

def create
  @bar = "1"
  # lack of render here currently means implicit render, but now the return
value is a String
  # so it would be rendered
end

etc.


> But it would be much cleaner, IMHO.
>
> Cheers,
> -foca
>
> > --
> > You received this message because you are subscribed to the Google
> Groups "Ruby on Rails: Core" group.
> > To post to this group, send email to [email protected].
> > To unsubscribe from this group, send email to
> [email protected].
> > For more options, visit this group at
> http://groups.google.com/group/rubyonrails-core?hl=en.
> >
>
> --
> You received this message because you are subscribed to the Google Groups
> "Ruby on Rails: Core" group.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/rubyonrails-core?hl=en.
>
>

-- 
You received this message because you are subscribed to the Google Groups "Ruby 
on Rails: Core" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/rubyonrails-core?hl=en.

Reply via email to