views:

126

answers:

2

I need to retain the Form data submitted in one view to be used in another view.

I'll be using POST method to submit the data. Is there anyway I can retrieve data from the POST method in Ruby, like in PHP I would use $title=$_POST["title"].

Any ideas?

Thanks and Cheers !

A: 

I think you just want the params hash? rubyonrails.org is down at the moment, but when it's back up take a read of the Action Controller Overview (or go to the google cache):

"Rails does not make any distinction between query string parameters and POST parameters, and both are available in the params hash in your controller"

Martin Carpenter
A: 

For this, you need to understand the rationale behind the MVC pattern. Depending on whether or not you want to persist your data in the database, you derive your model-class from ActiveRecord, but as persistence seems not be context of your question, here is what you could try:

First, define a model like this

class Foo
  # define variables here
  attr_accessor :param1 # create reader and writer methods for param1
end

In your controller action:

  def action1
    @foo = new Foo
    # pass parameters by using the params[] hash, e.g.
    @foo.param1 = params[:param1]
  end

You can then access the @foo object from every other view in your controller.

BTW, just found this screencast around the topic, #193 from railscasts.

poseid