0

I have a HTML page, in that page, there some options for User to select, this will affect how content will display.

I save those options by using instance variable in controller. For example :

class ShopController < ApplicationController

def index
   @option1 = option1 # instance variable option1, contains some information on the form
end

end

In this page, I have a form for user input information. When user presses submit button, ShopControler will process those information. But at that time, when I check @option1 variable --> NIL. It means : this is an another instance of ShopController.

Please give me a solution for the problem that I meet, that I can save information, and can reuse although user has summit form.

Thanks :)

2 Answers 2

2

Have you thought about storing it in a session variable?

session[:option1] = option1

Then when you're done with it just do a

session.delete(:option1)

This will allow you to use it through multiple requests.

Sign up to request clarification or add additional context in comments.

Comments

0

Typically when a user submits a form it will be routed to the create or update action. Unless you specifically have it routed to the index action your problem is most likely that you're not setting @option1 in the action the form is being submitted to.

If you find you are setting it in every action consider using a before_filter to set it.

Comments

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.