Create super-simple adding application

Hello people, rails noob here,
I am trying to create an extremely simple addition application by
having two text boxes allow users to put in any numbers, press a
button, and get them added together. This is my first attempted
application by myself, so I am probably making lots of simple
mistakes.

So far I have this in the view:

<%= text_field_tag :number_one %>
<%= text_field_tag :number_two %>

I have tried to call params[:number_one], and params[:number_two] in
my controller, but I get an error. A short bit of code showing what my
controller should look like would be great thanks!

On Oct 25, 1:14am, debalmoto [email protected] wrote:

So far I have this in the view:

<%= text_field_tag :number_one %>
<%= text_field_tag :number_two %>

I have tried to call params[:number_one], and params[:number_two] in
my controller, but I get an error.

What error?

Fred

Anytime I put params[:number_one] or two in my controller and start
the server up I get this error on my page:

undefined local variable or method `params’ for UserController:Class

On Oct 25, 5:03am, Frederick C. [email protected]

Ok, so I figured out what was causing the error, I wasnt calling
params[:number_one] in the right place. Fixing this took care of the
error. Now I can call them in my controller like so:

@a = params[:number_one].to_i
@b = params[:number_one].to_i
@sum = @a + @b

But when I put numbers in my text boxes, it always shows 0. I even put
this is my view:

<%= params[:number_one].to_i + params[:number_two].to_i %>

And it also always shows 0. What am I doing wrong?

Anytime I put params[:number_one] or two in my controller I get this
error on my page:

undefined local variable or method `params’ for
ApplicationController:Class

On Oct 25, 5:03am, Frederick C. [email protected]

On Oct 26, 3:18am, debalmoto [email protected] wrote:

<%= params[:number_one].to_i + params[:number_two].to_i %>

And it also always shows 0. What am I doing wrong?

I’d check the development.log file to see what parameters are actually
getting submitted.

Fred

It doesn’t say any numbers, the relevant log info just says it
processed the GET and got the layout.

On Oct 26, 4:32am, Frederick C. [email protected]

On 26 Oct, 20:56, debalmoto [email protected] wrote:

It doesn’t say any numbers, the relevant log info just says it
processed the GET and got the layout.

Sounds like the parameters aren’t getting sent
What does the rest of the view with the form look like?

Fred

On Oct 26, 10:48pm, debalmoto [email protected] wrote:

<%= text_field_tag(:number_one, value = 0) %> <%= text_field_tag(:number_two, value = 0) %>

<%= @sum %>

That’s all of it.

Time for HTML lesson 1: if you want inputs to get sent to the server,
they need to be enclosed in a form (modulo javascript trickery).

Fred

Frederick C. wrote in post #957392:

On Oct 26, 10:48pm, debalmoto [email protected] wrote:

<%= text_field_tag(:number_one, value = 0) %> <%= text_field_tag(:number_two, value = 0) %>

<%= @sum %>

That’s all of it.

Time for HTML lesson 1: if you want inputs to get sent to the server,
they need to be enclosed in a form (modulo javascript trickery).

Fred

Exactly.

So you may want to change the view code to look like this:

<%= form_tag(‘/’) do -%>

<%= text_field_tag(:number_one, value = 0) %> <%= text_field_tag(:number_two, value = 0) %> <%= submit_tag 'Calculate' %>

<% end %>

<%= @sum %>

Thank you guys so much for your help. I think I have everything
working now. It must be frustrating dealing with such simple issues.
Just one more question: Did you intend to put the " - " in <%=
form_tag(’/’) do -%> ? I removed it and it didn’t seem to change
anything.

Thanks again for the help.

<%= text_field_tag(:number_one, value = 0) %> <%= text_field_tag(:number_two, value = 0) %>

<%= @sum %>

That’s all of it.

My controller:

class UserController < ApplicationController
def home
a = params[:number_one].to_i
b = params[:number_one].to_i
@sum = a + b
end
end

On Oct 26, 5:40pm, Frederick C. [email protected]