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 6080415
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:03:31+00:00 2026-05-23T11:03:31+00:00

I want to create a simple calculator form in Rails 3.1 just for understanding.

  • 0

I want to create a simple calculator form in Rails 3.1 just for understanding. Via a form I want to get a number and multiplied it by two (for example).

I’ve created controller with index page (/index), then form in views:

<%= form_for @result do |f|%>
<%= f.label :number, 'Number' %>:
<%= f.text_field :number %>
<%= submit_tag 'Submit' %>
<%end%>
<%=@result%>

What I need to do with controller?

  def index
    @result = ''
  end
  def calculate
    @result = @number.to_i*2
  end
  • 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-23T11:03:32+00:00Added an answer on May 23, 2026 at 11:03 am

    This is not gonna work. form_for is used to build forms for models that extend ActiveRecord. Use form_tag('/calculate') instead.

    You need to define `match ‘calculate’ => ‘your_controller_name#calculate’ in config/routes.rb.

    Additionally, you need a view for your calculate action – calculate.html.erb (you can call it differently but you’ll have to specify render 'view_name'.

    Alternatively, if you want to use the same view file, use render :action => :index

    Forgot to mention.
    To access the data from the form, you use params[:key] hash.
    So in your case it would look like @result = params[:number] * 2

    This book is a great place to start with Rails.

    Also, these screencasts are pretty helpful too

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

Sidebar

Related Questions

I'm just creating a simple calculator in C# (windows form) I've created a User
I want to create a simple user registration form with First / Last name,
I want to create simple app able to edit images. Main view of app
JavaScript. I want to create simple script, that will be resize loaded image using
I want to create a simple app, where the user can take a photo.
I want to create a simple app that shows me the city of the
I want to create a simple Javascript program with a HTML interface. The program
I want to create a simple server application which runs on the desktop, and
I want to create a simple login functionality in WP7 app using remote MySQL
I want to create a simple bash script to launch a Java program on

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.