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!

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

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

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:

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

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.

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

<p>
  <%= text_field_tag(:number_one, value = 0) %>
  <%= text_field_tag(:number_two, value = 0) %>
</p>
<p>
  <%= @sum %>
</p>

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

<p>
<%= text_field_tag(:number_one, value = 0) %>
<%= text_field_tag(:number_two, value = 0) %>
</p>
<p>
<%= @sum %>
</p>

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 Cheung wrote in post #957392:

<p>
    <%= text_field_tag(:number_one, value = 0) %>
    <%= text_field_tag(:number_two, value = 0) %>
</p>
<p>
    <%= @sum %>
</p>

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 -%>
<p>
  <%= text_field_tag(:number_one, value = 0) %>
  <%= text_field_tag(:number_two, value = 0) %>
  <%= submit_tag 'Calculate' %>
</p>
  <% end %>
<p>
  <%= @sum %>
</p>

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.