I have a case where replicas of certain controller methods would be useful within the view. In particular, these are role-based user-access methods. For example: can_view? can_modify? These will be methods setup in the AccountSystem module which is included in the ApplicationController. These methods will be used as before_filters to determine if the user has access to do a certain thing or not. I would also like to provide these same methods to my views, but I don''t quite understand how the scope will work. My views don''t have access to the "can_view?" from AccountSystem. But if I put a can_view? method in a helper, how would it call the can_view? from AccountSystem? Also, would there be a simple way to duplicate these in one fell-swoop to get all the methods copied over? Jake -- 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 -~----------~----~----~----~------~----~------~--~---
On 1/20/07, Jake Janovetz <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> I would also like to provide these same methods to my views, but I don''t > quite understand how the scope will work.In your ApplicationController: helper_method :can_view?, :can_modify? -- Chris Wanstrath http://errtheblog.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 -~----------~----~----~----~------~----~------~--~---
On Sun, 2007-01-21 at 01:50 -0800, Chris Wanstrath wrote:> On 1/20/07, Jake Janovetz <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > I would also like to provide these same methods to my views, but I don''t > > quite understand how the scope will work. > > In your ApplicationController: > > helper_method :can_view?, :can_modify? > > -- > Chris Wanstrath > http://errtheblog.com >Ok Chris, I like helper method, but sometimes the list grows too long. I used to have following code in my application.rb helper_method :current_url,:rand_between,:url_without_port,:market_open_time_in_utc,:market_close_time_in_utc,:market_current_time_in_utc,:market_local_time_as_str,:redirect_to_login,:current_domain,:diode,:triode,:pipe_val in those cases, what would the best approach? Moving them to a plugin? --~--~---------~--~----~------------~-------~--~----~ 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 Jan 21, 2007, at 11:14 AM, Hemant Kumar wrote:> > On Sun, 2007-01-21 at 01:50 -0800, Chris Wanstrath wrote: >> On 1/20/07, Jake Janovetz <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: >> >>> I would also like to provide these same methods to my views, but >>> I don''t >>> quite understand how the scope will work. >> >> In your ApplicationController: >> >> helper_method :can_view?, :can_modify? >> >> -- >> Chris Wanstrath >> http://errtheblog.com >> > > Ok Chris, I like helper method, but sometimes the list grows too long. > > I used to have following code in my application.rb > > helper_method :current_url,:rand_between,:url_without_port,:market_ope > n_time_in_utc,:market_close_time_in_utc,:market_current_time_in_utc,:m > arket_local_time_as_str,:redirect_to_login,:current_domain,:diode,:tri > ode,:pipe_val > > in those cases, what would the best approach? Moving them to a plugin? >Hemant- You could store all of those methods in a module name WhateverModule. Then just include that in yoru controller and view helpers and it will bve shared without all the ugly helper calls: module WhateverModule def some_methods end end class ApplicationController < ... include WhateverModule end module ApplicationHelper include WhateverModule end Cheers- -- Ezra Zygmuntowicz -- Lead Rails Evangelist -- ez-NLltGlunAUd/unjJdyJNww@public.gmane.org -- Engine Yard, Serious Rails Hosting -- (866) 518-YARD (9273) --~--~---------~--~----~------------~-------~--~----~ 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 Sun, 2007-01-21 at 15:28 -0800, Ezra Zygmuntowicz wrote:> > On Jan 21, 2007, at 11:14 AM, Hemant Kumar wrote: > > > > > On Sun, 2007-01-21 at 01:50 -0800, Chris Wanstrath wrote: > >> On 1/20/07, Jake Janovetz <rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > >> > >>> I would also like to provide these same methods to my views, but > >>> I don''t > >>> quite understand how the scope will work. > >> > >> In your ApplicationController: > >> > >> helper_method :can_view?, :can_modify? > >> > >> -- > >> Chris Wanstrath > >> http://errtheblog.com > >> > > > > Ok Chris, I like helper method, but sometimes the list grows too long. > > > > I used to have following code in my application.rb > > > > helper_method :current_url,:rand_between,:url_without_port,:market_ope > > n_time_in_utc,:market_close_time_in_utc,:market_current_time_in_utc,:m > > arket_local_time_as_str,:redirect_to_login,:current_domain,:diode,:tri > > ode,:pipe_val > > > > in those cases, what would the best approach? Moving them to a plugin? > > > > > Hemant- > > You could store all of those methods in a module name > WhateverModule. Then just include that in yoru controller and view > helpers and it will bve shared without all the ugly helper calls: > > module WhateverModule > def some_methods > end > end > > class ApplicationController < ... > include WhateverModule > end > > > module ApplicationHelper > include WhateverModule > endHmm makes sense. Thanks. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---