# Redirect\_to, render -- Controller Questions

**URL:** <https://www.ruby-forum.com/t/redirect-to-render-controller-questions/139221>\
**Category:** Rails\
**Created:** [June 2, 2008, 3:06am UTC](https://www.ruby-forum.com/t/redirect-to-render-controller-questions/139221 "2008-06-02T03:06:28Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dougd1101](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ba9def/32.png) [@dougd1101](https://www.ruby-forum.com/u/dougd1101)\
**Post date:** [June 2, 2008, 3:06am UTC](https://www.ruby-forum.com/t/redirect-to-render-controller-questions/139221/1 "2008-06-02T03:06:28Z")

</div>

So I am just learning RoR and how I learn best is to come up with a  
problem and use another language to accomplish this. So I decided to  
do “Digg” type of site where people post a comment and people  
respond. So in my controller I have an action called

view\_comments,

view\_comments takes several parameters to view the page.  
params[:comment][:ptype\_id],  
params[:user][:id]

While persisting a comment, I would like the user to be redirected  
back to view\_comments. However I have tried to pass parameters to  
redirect\_to and render and none have worked.

What would that look like?

```
  if @comment.save
    flash[:notice] = 'Comment was successfully created. '
    redirect_to :action => 'view_comments', ??????????
  else
    render :action => 'new'
  end

```

Thank you in advance.

---

<div class="post-metadata">

**Author:** ![dougd1101](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ba9def/32.png) [@dougd1101](https://www.ruby-forum.com/u/dougd1101)\
**Post date:** [June 2, 2008, 3:33am UTC](https://www.ruby-forum.com/t/redirect-to-render-controller-questions/139221/2 "2008-06-02T03:33:45Z")

</div>

On Sun, 2008-06-01 at 18:05 -0700, dougd1101 wrote:

> ```
> else
> render :action => 'new'
> end
> 
> ```

* * *

redirect\_to :action =\> ‘view\_comments’,  
:comment =\> {:ptype\_id =\> SOMETHING},  
:user =\> {:id =\> SOMETHING}

You’re making things complicated with hashes within hashes

Craig

---

<div class="post-metadata">

**Author:** ![dougd1101](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ba9def/32.png) [@dougd1101](https://www.ruby-forum.com/u/dougd1101)\
**Post date:** [June 5, 2008, 3:27am UTC](https://www.ruby-forum.com/t/redirect-to-render-controller-questions/139221/3 "2008-06-05T03:27:40Z")

</div>

Craig,  
You suggestion doesn’t quite work. It leaves me with errors like:

Couldn’t find user without an ID

Request  
Parameters: {“user”=\>“4”, “comment”=\>“ptype\_id1”}

But now you have me wondering if I am missing the power of RoR when I  
have the form fields with names like

Then I get those values inside the controller like this  
params[:comment][:ptype\_id]

I was just following the scaffolding that was already created by RoR.

Thanks

---

<div class="post-metadata">

**Author:** ![dougd1101](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/d/ba9def/32.png) [@dougd1101](https://www.ruby-forum.com/u/dougd1101)\
**Post date:** [June 5, 2008, 3:21pm UTC](https://www.ruby-forum.com/t/redirect-to-render-controller-questions/139221/4 "2008-06-05T15:21:07Z")

</div>

Hi

On Wed, 2008-06-04 at 18:27 -0700, dougd1101 wrote:

> have the form fields with names like  
> Thanks
> 
> > > view\_comments takes several parameters to view the page.  
> > > flash[:notice] = 'Comment was successfully created. ’  
> > > You’re making things complicated with hashes within hashes

* * *

ï»¿I don’t know what controller you are working with so I’m just going to  
assume ‘posts’

\<%= text\_field ‘posts’, ‘user\_id’ %\>  
\<%= hidden\_field ‘posts’, 'ptype\_id %\>

and then the params that get returned to the controller are

params[:posts]  
or specific params are  
params[:posts][:user\_id]  
params[:posts][:ptype\_id]

you can always see what params are returned by putting at the bottom of  
your ‘view code’

\<%= debug params %\>  
or  
\<%= debug @posts %\>

Craig
