I have a trivial question: if i have defined something in my controller, like def calendar my_time = Time.now end how do I use that variable in my view? I tried <%= my_time %> But that simply returns an error. Thanks -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Sat, Jan 19, 2013 at 6:44 PM, Pierre-Andre M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote:> I have a trivial question: > > if i have defined something in my controller, like > > def calendar > my_time = Time.now > > end > >That variable only works on that method, you need an instance variable def calendar @my_time = Time.now end in view calendar.html.erb <%= @my_time%> ---------------------------- Javier -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Hello Pierre You could either use an instance variable like this: @my_time = Time.now Then in your view access it with: <%= @my_view %> Or use the decent_exposure gem which I recommend since this lets you access your variables without exposing instance variables in the view context. 2013/1/19 Pierre-Andre M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>> I have a trivial question: > > if i have defined something in my controller, like > > def calendar > my_time = Time.now > > end > > how do I use that variable in my view? > > I tried <%= my_time %> > > But that simply returns an error. > > Thanks > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On Sat, Jan 19, 2013 at 6:13 PM, Benjamin Iandavid Rodriguez <ian.rgz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Or use the decent_exposure gem which I recommend since this lets you access > your variables without exposing instance variables in the view context.Because attr_accesor doesn''t exist, so the entire premise isn''t broken o.O. /end-broken-logic -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
helper_method :calendar Is what you want. On Jan 19, 2013 6:44 PM, "Pierre-Andre M." <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> I have a trivial question: > > if i have defined something in my controller, like > > def calendar > my_time = Time.now > > end > > how do I use that variable in my view? > > I tried <%= my_time %> > > But that simply returns an error. > > Thanks > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
It''s a good gem but it''s a bit heavy handed since it (nicely) provides and, iirc, wraps helper_method. On Jan 19, 2013 7:20 PM, "Jordon Bedwell" <envygeeks-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> On Sat, Jan 19, 2013 at 6:13 PM, Benjamin Iandavid Rodriguez > <ian.rgz-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > > Or use the decent_exposure gem which I recommend since this lets you > access > > your variables without exposing instance variables in the view context. > > Because attr_accesor doesn''t exist, so the entire premise isn''t broken o.O. > /end-broken-logic > > -- > 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > To unsubscribe from this group, send email to > rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org > For more options, visit https://groups.google.com/groups/opt_out. > > >-- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
Javier Quarite wrote in post #1092882:> On Sat, Jan 19, 2013 at 6:44 PM, Pierre-Andre M. > <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org>wrote: > >> I have a trivial question: >> >> if i have defined something in my controller, like >> >> def calendar >> my_time = Time.now >> >> end >> >> > That variable only works on that method, you need an instance variable > > def calendar > @my_time = Time.now > end > > in view calendar.html.erb > > <%= @my_time%>That worked awesome thanks a bunch...also, I appreciate the follow up dialogue on using different methods as well...Im sure I''ll appreciate this more once I''m more well-versed. -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.
On 20 January 2013 01:52, Pierre-Andre M. <lists-fsXkhYbjdPsEEoCn2XhGlw@public.gmane.org> wrote:> Javier Quarite wrote in post #1092882: >> ... >> <%= @my_time%> > > That worked awesome thanks a bunch...also, I appreciate the follow up > dialogue on using different methods as well...Im sure I''ll appreciate > this more once I''m more well-versed.I suggest that you work right through a good rails tutorial such as railstutorial.org, which is free to use online, which will show you the basics or Rails. Make sure that any tutorial you use is for rails 3 and that you install the correct version of rails for the tutorial. Colin -- 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-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org To unsubscribe from this group, send email to rubyonrails-talk+unsubscribe-/JYPxA39Uh5TLH3MbocFF+G/Ez6ZCGd0@public.gmane.org For more options, visit https://groups.google.com/groups/opt_out.