Controller level variables

Hello,

I am new to ruby and I want to know how can I define a variable whose
scope is restricted to a particular controller.

Scenario:
What I am trying to achieve is this - based on the parameters
specified by user, I make some queries to database. The results of the
query are consumed by different methods in that controller. What I
want to achieve is - I want to make all the queries before the page
loads and store them in some variable and I want to access these
variables across different methods in the controller.

Thanks,
Jaikishan

Hello,

I am new to ruby and I want to know how can I define a variable whose
scope is restricted to a particular controller.

Scenario:
What I am trying to achieve is this - based on the parameters
specified by user, I make some queries to database. The results of the
query are consumed by different methods in that controller. What I
want to achieve is - I want to make all the queries before the page
loads and store them in some variable and I want to access these
variables across different methods in the controller.

Sounds like you want an instance variable (it also sounds like you are
spending too much time worrying about details without knowing about
the basics)

Fred

and I want to access these
variables across different methods in the controller.

You might also want to google for "skinny controller fat model" before
you get too deep into your design...

as Fred mentioned, get a basic app up and running (scaffolding works
fine for this, and will write the example code for you), then extend
from there. Rails has a mindset you need to understand in order to build
effectively.

I recently spoke with a friend who heard about Rails and tried it out,
then complained when it was too difficult. Turned out he was trying to
apply the same organization to his Rails code as he used on other
projects not built in Rails. An hour or so refactoring his code to "the
Rails way", and he was astonished at the ease of use.