# Render a url?

**URL:** <https://www.ruby-forum.com/t/render-a-url/144662>\
**Category:** Rails\
**Created:** [July 31, 2008, 11:13pm UTC](https://www.ruby-forum.com/t/render-a-url/144662 "2008-07-31T23:13:35Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 31, 2008, 11:13pm UTC](https://www.ruby-forum.com/t/render-a-url/144662/1 "2008-07-31T23:13:35Z")

</div>

```
    uri = session[:original_uri]
    session[:original_uri] = nil
    render (uri || { :action => :index })

```

is it possible?

Thanks!

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 31, 2008, 11:15pm UTC](https://www.ruby-forum.com/t/render-a-url/144662/2 "2008-07-31T23:15:45Z")

</div>

no.  
why can’t you use redirect\_to?

On Thu, Jul 31, 2008 at 4:13 PM, Justin To  
\<removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 31, 2008, 11:20pm UTC](https://www.ruby-forum.com/t/render-a-url/144662/3 "2008-07-31T23:20:50Z")

</div>

Brian H. wrote:

> no.  
> why can’t you use redirect\_to?
> 
> On Thu, Jul 31, 2008 at 4:13 PM, Justin To  
> \<removed\_email\_address@domain.invalid

def save\_requirement  
@post = Post.new(params[:post])

```
    if @post.save
      redirect_to :action => :index, :id => @post.id
    else
      params[:not_saved] = true
      render :action => :index
    end

```

end

If I redirect\_to then the error\_messages\_for ‘post’ won’t be shown  
anymore. Any workarounds?

Thanks!

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [July 31, 2008, 11:25pm UTC](https://www.ruby-forum.com/t/render-a-url/144662/4 "2008-07-31T23:25:08Z")

</div>

Not following you. Why would you need to change the rendering? It should  
render just fine with the code you have below. No need to redirect on  
failure, only on success, just as your code below specifies. What  
exactly  
are you trying to do?

A lot of your questions come without context,., consider adding some  
background to the problem you’re trying to solve when you show code.

On Thu, Jul 31, 2008 at 4:20 PM, Justin To  
\<removed\_email\_address@domain.invalid

---

<div class="post-metadata">

**Author:** ![jturney](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/j/e99b99/32.png) [@jturney](https://www.ruby-forum.com/u/jturney)\
**Post date:** [August 1, 2008, 12:28am UTC](https://www.ruby-forum.com/t/render-a-url/144662/5 "2008-08-01T00:28:07Z")

</div>

Brian H. wrote:

> Not following you. Why would you need to change the rendering? It should  
> render just fine with the code you have below. No need to redirect on  
> failure, only on success, just as your code below specifies. What  
> exactly  
> are you trying to do?
> 
> A lot of your questions come without context,., consider adding some  
> background to the problem you’re trying to solve when you show code.
> 
> On Thu, Jul 31, 2008 at 4:20 PM, Justin To  
> \<removed\_email\_address@domain.invalid

Mmm…well I have the index page. And when a user clicks “new” (:action  
=\> :new), a table slides\_down with a form for the Post model in the  
index page. There’s no ‘new.html.erb’. Then when a user submits (:action  
=\> :save\_requirement), it is suppose to redirect\_to :action =\> :index if  
saved successfully. There is no ‘save\_requirement.html.erb’ so I need to  
render something otherwise I get the ‘Missing Template’ error if the  
Post fails to save. Since my form was presented through ajax on my index  
page, I need to display my error messages for the unsuccessful Post on  
the table that slid\_down in the index page that holds the Post form.  
Therefore, I have to render :action =\> :index

At least, that’s the only way I’ve managed to do it. There is one bug I  
found with this method: the url stays the same ‘/save\_requirement’, when  
I don’t want that there anymore if it was unsuccessful.

Hope that’s clearer,

thanks
