praveen k.
2011-Jul-27 11:50 UTC
how to get a value of a variable from a controller to different view?
Hi, a small question.How to get a value of a variable from a controller to different view? here is my code. controller: class CalController < ApplicationController def add @b=params[:number1].to_f @c=params[:number2].to_f if (@b==0 || @c==0) render :action=>"add1" else if params[:exp]== ''1'' @a=@b+@c elsif params[:exp]== ''2'' @a=@b-@c elsif params[:exp]== ''3'' @a=@b*@c elsif params[:exp]== ''4'' @a=@b/@c else @s="please select a choice" redirect_to :controller=> "home",:action =>"index" end end end def add1 end end different view: <html> <body> <h1><center><font color="blue">CALCULATOR</font></center></h1> <%= form_tag(:controller=>"cal",:action => "add") do %> <%= label_tag(:q1, "Enter first number:") %> <%= text_field_tag(:number1) %> <br><br> <%= label_tag(:q2, "Enter second number:") %> <%= text_field_tag(:number2) %> <br></br> <%= label_tag(:q3, "Calculations:") %><br></br> <div id="radio_buttons"> <%= radio_button_tag ''exp'', 1 %>Add<br></br> <%= radio_button_tag ''exp'', 2 %>Sub<br></br> <%= radio_button_tag ''exp'', 3 %>Mul<br></br> <%= radio_button_tag ''exp'', 4 %>div<br></br> </div> <%= submit_tag("Submit") %> <%= params[:s] %> <% end %> </body> </html> please help me out with this.i have used params but it is not working. Thankyou. -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
Chirag Shah
2011-Jul-27 12:06 UTC
Re: how to get a value of a variable from a controller to different view?
If you redirect your page then you can not get that variable value to your view Only on render you have that variable value And you can not have value in params unless you pass it in the arguments at the time of the redirection - Chirag Shah -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
praveen k.
2011-Jul-27 12:12 UTC
Re: how to get a value of a variable from a controller to different view?
Chirag Shah wrote in post #1013322:> If you redirect your page then you can not get that variable value to > your view > Only on render you have that variable value > And you can not have value in params unless you pass it in the arguments > at the time of the redirection > > - Chirag Shahhi Chirag then how i do that? -- 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 post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.
shrimpy
2011-Jul-27 14:30 UTC
Re: how to get a value of a variable from a controller to different view?
for this part: @s="please select a choice" redirect_to :controller=> "home",:action =>"index" i think you suppose to use notice or flash redirect_to :controller=> "home",:action =>"index", :notice=> ''please select a choice'' or flash[:s] = "please select a choice" redirect_to :controller=> "home",:action =>"index" On Jul 27, 10:12 pm, "praveen k." <li...-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Chirag Shah wrote in post #1013322: > > > If you redirect your page then you can not get that variable value to > > your view > > Only on render you have that variable value > > And you can not have value in params unless you pass it in the arguments > > at the time of the redirection > > > - Chirag Shah > > hi Chirag > then how i do that? > > -- > Posted viahttp://www.ruby-forum.com/.-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@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.
Hi All, Is there a setting somewhere that I can change that will prevent scaffold-generated migrations from defaulting to allowing NULL values for columns? Thanks! **Leigh -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en.