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:

CALCULATOR

<%= form_tag(:controller=>“cal”,:action => “add”) do %>
<%= label_tag(:q1, “Enter first number:”) %>
<%= text_field_tag(:number1) %>


<%= label_tag(:q2, “Enter second number:”) %>
<%= text_field_tag(:number2) %>


<%= label_tag(:q3, “Calculations:”) %>

<%= radio_button_tag 'exp', 1 %>Add
<%= radio_button_tag 'exp', 2 %>Sub
<%= radio_button_tag 'exp', 3 %>Mul
<%= radio_button_tag 'exp', 4 %>div

<%= submit_tag(“Submit”) %>
<%= params[:s] %>
<% end %>

please help me out with this.i have used params but it is not working.
Thankyou.

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

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 can i do that?

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”

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