Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7174079
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T15:57:28+00:00 2026-05-28T15:57:28+00:00

I am attempting to do some calculations on a simple ruby screen. Lets say

  • 0

I am attempting to do some calculations on a simple ruby screen.
Lets say for fun, i want to create a form that lets the user convert meters to feet.
Of course I don’t want to store the values in a database. Nor would I want to create a table just for this.

So my question.. How do I create a single text field tied to a controller.
With a button.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T15:57:29+00:00Added an answer on May 28, 2026 at 3:57 pm

    Here’s a really simple example of making a form adding two numbers:

    rails new math_app -O
    cd math_app
    rails generate controller Add form result
    

    The last line generates a controller with 2 actions –

    • “form”- to show the form
    • “result” – to show the results

    In another command prompt window, open the ‘math_app’ directory and start the server:

    rails server
    

    You can open a browser to ‘localhost:3000/add/form’ and ‘localhost:3000/add/result’ to see the default pages Rails generated for you. As you edit things below you can revisit these pages (and don’t even have to restart the server) to see what they produce.

    Edit ‘app\views\add\form.html.erb’ to create the form we want to show.

    <%= form_tag add_result_path do %>
      <%= number_field_tag :first %>
      +
      <%= number_field_tag :second %>
      <%= submit_tag "add" %>
    <% end %>
    

    Edit ‘config/routes.rb’ to make the ‘result’ action take POST requests from the form above.

    Change –

    get "add/result"
    

    to-

    post "add/result"
    

    Edit ‘app\controllers\add_controller.rb’ result method to retrieve the two numbers from the form data and add them together.

    def result
      @first = params[:first].to_i
      @second = params[:second].to_i
      @result = @first + @second
    end
    

    Edit ‘app\views\add\result.html.erb’ to show the result.

    <%= @first %> + <%= @second %> = <%= @result %>
    <br/>
    <%= link_to 'back', add_form_path %>
    

    Done!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am attempting to develop an application that makes use of some simple trig
I'm attempting to display some text in my program using (say) Windows GDI and
I'm attempting to display some text in my program using (say) Windows GDI and
I'm attempting to pull some data from a SQLite database so that I can
I'm attempting to build some C++ code that requires the Windows 7.0 SDK header
I am attempting to add some entities that I have created. When I try
I am attempting to get some information from a website, the info that I
I am attempting to write some code that will expediently process video frames. I
I am attempting to write some jQuery code that will expand a paragraph when
I am attempting to write some Java code that takes an image from a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.