Hi, Still learning rails and have a basic question. Can I pass any variable thru the params hash to an action? eg "in_progress" View: <%= f.submit "Add image/video", :in_progress=> "true" %> Controller: def update @question = Question.find(params[:id]) if params[:in_progress] == "true" @question.attributes = params[:question] if @question.save(:validate => false) redirect_to gallery_path(session[:minisection_id]), id: "image_gallery" end else.... Im trying to set flag to bypass validation and redirect in update action. Thanks -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Dave Castellano wrote in post #1106220:> Hi, > > Still learning rails and have a basic question. Can I pass any variable > thru the params hash to an action?You can do that the same way you would do it in HTML, use a hidden form field. Rails has a helper for that: http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-hidden_field -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
I did try that. For some reason update action does not see params[:in_progress] == "true" as true. It is ''true'' in params hash though. Any other thoughts? Been trying to figure this out all week. In view: <%= f.submit "Add image/video", :id=> ''add_image_commit'' %> jQuery sets hidden field "in_progress" to true: $("#add_image_commit").on "click", (event) -> # User clicks "Add image" button. $("#in_progress").val("true") hidden field IS set to true. In controller: def update @question = Question.find(params[:id]) if params[:in_progress] == "true" @question.attributes = params[:question] if @question.save(:validate => false) redirect_to gallery_path(session[:minisection_id]), id: "image_gallery" end else..... Params hash: in_progress: ''true'' commit: Add image/video _wysihtml5_mode: ''1'' action: update controller: questions -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Robert Walker wrote in post #1106231:> Dave Castellano wrote in post #1106220: >> Hi, >> >> Still learning rails and have a basic question. Can I pass any variable >> thru the params hash to an action? > > You can do that the same way you would do it in HTML, use a hidden form > field. Rails has a helper for that: > >http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-hidden_field I did try that. For some reason update action does not see params[:in_progress] == "true" as true. It is ''true'' in params hash though. Any other thoughts? Been trying to figure this out all week. In view: <%= f.submit "Add image/video", :id=> ''add_image_commit'' %> jQuery sets hidden field "in_progress" to true: $("#add_image_commit").on "click", (event) -> $("#in_progress").val("true") Hidden field IS set to true. In controller: def update @question = Question.find(params[:id]) if params[:in_progress] == "true" @question.attributes = params[:question] if @question.save(:validate => false) redirect_to gallery_path(session[:minisection_id]), id: "image_gallery" end else..... Params hash: in_progress: ''true'' commit: Add image/video _wysihtml5_mode: ''1'' action: update controller: questions -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Dave Castellano wrote in post #1106346:> Robert Walker wrote in post #1106231: >> Dave Castellano wrote in post #1106220: >>> Hi, >>> >>> Still learning rails and have a basic question. Can I pass any variable >>> thru the params hash to an action? >> >> You can do that the same way you would do it in HTML, use a hidden form >> field. Rails has a helper for that: >> >> >http://api.rubyonrails.org/classes/ActionView/Helpers/FormHelper.html#method-i-hidden_field> > I did try that. For some reason update action does not see > params[:in_progress] == "true" as true. It is ''true'' in params hash > though. Any other thoughts? Been trying to figure this out all week. > > In view: > <%= f.submit "Add image/video", :id=> ''add_image_commit'' %> > > jQuery sets hidden field "in_progress" to true: > $("#add_image_commit").on "click", (event) -> > $("#in_progress").val("true") > > Hidden field IS set to true. > > In controller: > def update > @question = Question.find(params[:id]) > if params[:in_progress] == "true" > @question.attributes = params[:question] > if @question.save(:validate => false) > redirect_to gallery_path(session[:minisection_id]), id: > "image_gallery" > end > else..... > > Params hash: > in_progress: ''true'' commit: Add image/video _wysihtml5_mode: ''1'' > action: update controller: questionsGot it! if params[:question][:in_progress] == ''true'' Thanks. -- Posted via http://www.ruby-forum.com/. -- You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.