0

I have 3 pages:

[Page 1] Index

[Page 2] User enter value in a form.

[Page 3] Do calculation on the value entered and output it on this page.

I as wondering how do i do this? I do not want to save the data in any database.

Thank you =)

*Added info 20100628 based on feedback. Thank you! *

for PHP, I could user $_GET and %_POST function. I am not sure how to do it on ROR. [Page 1: index.html]

Amount in bank: Interest rate (%):

[Page 2: interest_cal.php] In 10 yrs, the total amount in your bank would be _______

6 Answers 6

2

welcome to stackoverflow. This is a programming QA Website, so it would be nice to see some Code, to see more clearly what You want. But I think what you want is a tableless model. There are two good screencasts by railscasts:

  1. Tableless Model (Rails 2)
  2. Active Model (Rails 3)
Sign up to request clarification or add additional context in comments.

Comments

0

Just declare attribute in your model and use it.

attr_accessor :value

Comments

0

if you use params[:field_name] in Rails, this is similar to $_REQUEST['field_name'] in PHP (except params in Rails doesn't include cookies, as $_REQUEST does)

Comments

0

I do not want to save the data in any database.

its simple don't create any model. or if you must create model. create model without inheritance from ActiveRecord::Base

class UserModel 

but not

class UserModel <  ActiveRecord::Base

for PHP, I could user $_GET and %_POST function.

use params variable in controller

Comments

0

If you don't have a model, but just simply a variable, I would prefer using form_tag instead of form_for

<%= form_tag :action => "your_page_3_action" $>
    <%= text_field_tag :some_var %>

Something like that. And then you could get back the :some_var through:

def your_page_3_action
  params[:some_var] # that's your input valut

Comments

0

Try something like this

Page1 -> index

Page2 ->

say you have a model called user which is not inherited from ActiveRecord, so it will be looks like this

class User
  attr_accessor :my_value   
end

and you will have a form like this

<% form_for(@user) do |f| %>
  <p>
    <%= f.text_field :my_value %>
  </p>
  <p>
    <%= f.submit 'send value' %>
  </p>
<% end %>

** sorry i had to remove some tags

and in your form post action (in controller), you can get the value as

params[:user][:my_value]

hope this helps

cheers

sameera

2 Comments

you should format your code properly the next time. It can be done by indenting each code line by 4 spaces or mark the code and hit the code button of the editor (the one with the ones and zeroes on it)
Thank you sameera207 and Jens F.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.