Redirect_to, render -- Controller Questions

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.

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

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

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