Juan pablo Gómez
2008-Jan-22 23:33 UTC
Passing data to a view: How prevent the instance variables ?
Greetings, i want pass data to my view without using instace variables. Usually I make renders to partials for pass local variables and preventing use instace variables : Example: render( :partial => "filename", :locals => {:paramName = @anyVar} ) I''ve this method in my controller(controller.rb): def anyMethod var1=5 var2=6 end There''s any way to pass var1 and var2 to the default view anyMethod.rhtml without use instace variables? Thanks for any answer, Juan Pablo -- 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 -~----------~----~----~----~------~----~------~--~---
Nathan Esquenazi
2008-Jan-23 10:56 UTC
Re: Passing data to a view: How prevent the instance variabl
I have to ask... why are you so keen on avoiding instance variables? Sorry, I am just curious because they are so widely the standard way of passing data between controller and view. I actually don''t know of any other way but that might be simply that I never had a need. -- 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 -~----------~----~----~----~------~----~------~--~---
Juan pablo Gómez
2008-Jan-23 14:26 UTC
Re: Passing data to a view: How prevent the instance variabl
Nathan Esquenazi wrote:> I have to ask... why are you so keen on avoiding instance variables? > Sorry, I am just curious because they are so widely the standard way of > passing data between controller and view. I actually don''t know of any > other way but that might be simply that I never had a need.I just want work in a very modular way (OO mode). And I don''t need than all my variables have to be with public access, that''s the reason -- 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 -~----------~----~----~----~------~----~------~--~---
> I just want work in a very modular way (OO mode). And I don''t need than > all my variables have to be with public access, that''s the reasonThere is nothing wrong with passing instance variables to the view. However, I do think its good practice to limit the number of variables you use. If your passing a large number of variables they can probably be wrapped into an object, then you can just pass the object. For example: def some_controller_method @height = 5 @width = 10 @depth = 2 end compared to: def some_controller_method @box = Box.new(:height => 5, :width => 10, :depth => 2) end Then your view calls @box.height, etc... Aaron --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---