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 --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
On Sep 22, 7:33 am, Jaikishan <jai....-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> 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> Thanks, > Jaikishan--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
> 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. -- Posted via http://www.ruby-forum.com/. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group. To post to this group, send email to rubyonrails-talk-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---