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.