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. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sun, 2008-06-01 at 18:05 -0700, dougd1101 wrote:> 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---- redirect_to :action => ''view_comments'', :comment => {:ptype_id => SOMETHING}, :user => {:id => SOMETHING} You''re making things complicated with hashes within hashes Craig --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
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 <input id="comment_ptype_id" name="comment[ptype_id]" type="hidden" value="1" /> <input id="u_id" name="user[id]" type="hidden" /> 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 On Jun 1, 8:32 pm, Craig White <craigwh...-BQ75lA0ptkhBDgjK7y7TUQ@public.gmane.org> wrote:> On Sun, 2008-06-01 at 18:05 -0700, dougd1101 wrote: > > 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 > > ---- > redirect_to :action => ''view_comments'', > :comment => {:ptype_id => SOMETHING}, > :user => {:id => SOMETHING} > > You''re making things complicated with hashes within hashes > > Craig--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Hi On Wed, 2008-06-04 at 18:27 -0700, dougd1101 wrote:> 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 > > <input id="comment_ptype_id" name="comment[ptype_id]" type="hidden" > value="1" /> > <input id="u_id" name="user[id]" type="hidden" /> > > 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 > > On Jun 1, 8:32 pm, Craig White <craigwh...-BQ75lA0ptkhBDgjK7y7TUQ@public.gmane.org> wrote: > > On Sun, 2008-06-01 at 18:05 -0700, dougd1101 wrote: > > > 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 > > > > ---- > > redirect_to :action => ''view_comments'', > > :comment => {:ptype_id => SOMETHING}, > > :user => {:id => SOMETHING} > > > > 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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk-unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---