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', 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.