Gioele Barabucci
2007-May-22 15:16 UTC
ApplicationHelper not available to views and models?
Hello, I have some constants that I need to share in almost all the pieces of my application. So I decided to put them in ApplicationHelper. From what I understand, ApplicationHelper is used to store helpers available to the whole application. Somehow my models and my views are unable to access the constants defined in ApplicationHelper. My workaround for models is to ''include ApplicationHelper'' inside the model declaration. For views I haven''t found a working solution aside copy''n''pasting these constants inside the views. What is the correct way to use ApplicationHelper and make constants available to the entire application? -- Gioele -- 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 -~----------~----~----~----~------~----~------~--~---
jimcfisher-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org
2007-May-22 17:26 UTC
Re: ApplicationHelper not available to views and models?
stuff placed in application_helper.rb is only available to your Views / Helpers. If you want a constant to be available to everything put it in your config/environment.rb file Or if you only need it in your controllers controller/application.rb. Just models you can create a module in your /lib folder and mix it in with ActiveRecord::Base to make it available to all your models. I know you wanted them all but I figured I''d just cover the others as a bonus. Hope I helped, Jim On May 22, 10:16 am, Gioele Barabucci <rails-mailing-l...@andreas- s.net> wrote:> Hello, > > I have some constants that I need to share in almost all the pieces of > my application. So I decided to put them in ApplicationHelper. From what > I understand, ApplicationHelper is used to store helpers available to > the whole application. > > Somehow my models and my views are unable to access the constants > defined in ApplicationHelper. My workaround for models is to ''include > ApplicationHelper'' inside the model declaration. For views I haven''t > found a working solution aside copy''n''pasting these constants inside the > views. > > What is the correct way to use ApplicationHelper and make constants > available to the entire application? > > -- > Gioele > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Gioele Barabucci
2007-May-22 20:27 UTC
Re: ApplicationHelper not available to views and models?
unknown wrote:> stuff placed in application_helper.rb is only available to your > Views / Helpers.Constants in ApplicationHelper doesn''t seem to be available to my views. Right now they are inside module ApplicationHelper, should I move them outside? One of my views fails with uninitialized constant ActionView::Base::CompiledTemplates::MyConst on <%= options_from_collection_for_select MyConst, :first, :last %>> If you want a constant to be available to everything put it in your > config/environment.rb fileYs, that would surely work, but, isn''t there a more "localized" way to do it? I''d like to work inside app/ as much as possible. I do not mind having to explicitly ''include'' or ''require'' stuff as long as there are standard directories where to put these global files.> I know you wanted them all but I figured I''d just cover the others as > a bonus.I love when I browse old forums and find complete answers like this! Thank you. -- Gioele -- 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 -~----------~----~----~----~------~----~------~--~---
tonypm
2007-May-27 11:52 UTC
Re: ApplicationHelper not available to views and models? How to - Application wide constants
Hi, now I may get corrected or put down for this, but I have put some constants into my models where I wanted to have them available for mapping view information against model attributes. If you want some constants available globally (something I have been thinking about myself), but don''t view them as being Environment type variables, then could you not create a model Class to contain the models and then reference them by that class. That would seem to me to be a fairly clean approach, but someone may say that this goes against the ''rules''? I would be interested to know. tonypm On May 22, 9:27 pm, Gioele Barabucci <rails-mailing-l...@andreas- s.net> wrote:> unknown wrote: > > stuff placed in application_helper.rb is only available to your > > Views / Helpers. > > Constants in ApplicationHelper doesn''t seem to be available to my views. > Right now they are inside module ApplicationHelper, should I move them > outside? > > One of my views fails with > > uninitialized constant ActionView::Base::CompiledTemplates::MyConst > > on > > <%= options_from_collection_for_select MyConst, :first, :last %> > > > If you want a constant to be available to everything put it in your > > config/environment.rb file > > Ys, that would surely work, but, isn''t there a more "localized" way to > do it? I''d like to work inside app/ as much as possible. > > I do not mind having to explicitly ''include'' or ''require'' stuff as long > as there are standard directories where to put these global files. > > > I know you wanted them all but I figured I''d just cover the others as > > a bonus. > > I love when I browse old forums and find complete answers like this! > Thank you. > > -- > Gioele > > -- > Posted viahttp://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 -~----------~----~----~----~------~----~------~--~---
Michel B
2007-May-27 13:54 UTC
Re: ApplicationHelper not available to views and models? How to - Application wide constants
In the application controller you could put this line of code: ''include ApplicationHelper'' in order to be able to use the helper methods in the controller. Another approach is to put your code in the /lib folder and do a require ''filename'' in the controller or model. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Gabriel Gironda
2007-May-27 14:21 UTC
Re: ApplicationHelper not available to views and models? How to - Application wide constants
I''d suggest not just wholesale-including ApplicationHelper into ApplicationController. Any public methods in controllers in Rails end up being exposed as actions, which may have inadvertent side effects, unless you call hide_action on them, and it''s generally better practice to separate view and controller. - Gabriel On 5/27/07, Michel B <m.barbosavicenteduarte-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > In the application controller you could put this line of code: > ''include ApplicationHelper'' in order to be able to use the helper > methods in the controller. Another approach is to put your code in > the /lib folder and do a require ''filename'' in the controller or > model. > > > > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Brian Ablaza
2007-May-29 22:21 UTC
Re: ApplicationHelper not available to views and models?
See this thread: http://www.ruby-forum.com/topic/106831 Ignore the "crazy" talk. This shows how to create global variables. Gioele Barabucci wrote:> Hello, > > I have some constants that I need to share in almost all the pieces of > my application. So I decided to put them in ApplicationHelper. From what > I understand, ApplicationHelper is used to store helpers available to > the whole application. > > Somehow my models and my views are unable to access the constants > defined in ApplicationHelper. My workaround for models is to ''include > ApplicationHelper'' inside the model declaration. For views I haven''t > found a working solution aside copy''n''pasting these constants inside the > views. > > What is the correct way to use ApplicationHelper and make constants > available to the entire application? > > -- > Gioele-- 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 -~----------~----~----~----~------~----~------~--~---
Polar Humenn
2008-Jun-29 21:21 UTC
Re: ApplicationHelper not available to views and models?
Everything I have read so far, states that the functions in the "ApplicationHelper" module are available to all views in the application. I guess they get loaded into the specific controller automagically and public methods become "protected". So, I put a function in there, and lo and behold my view cannot see it. Grrrr. However, if I put the function in the helper module specific to the view, voila, it works. This must be the "rails" magic. So, is something is wrong, or have I not read something important? Is there a configuration variable for this? I''m using Rails 2.1.0. -- 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 don''t think there is any configuration variable for this. Any method declared in ApplicationHelper module should be available to all views until and unless you have done something wrong somewhere. On Mon, Jun 30, 2008 at 2:51 AM, Polar Humenn < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > Everything I have read so far, states that the functions in the > "ApplicationHelper" module are available to all views in the > application. I guess they get loaded into the specific controller > automagically and public methods become "protected". > > So, I put a function in there, and lo and behold my view cannot see it. > Grrrr. > > However, if I put the function in the helper module specific to the > view, voila, it works. This must be the "rails" magic. > > So, is something is wrong, or have I not read something important? > Is there a configuration variable for this? > > I''m using Rails 2.1.0. > -- > Posted via http://www.ruby-forum.com/. > > > >-- Arpit Jain Senior Undergraduate Student Department of Computer Science & Engineering Indian Institute of Technology, Kharagpur, India. Web: http://www.arpitjain.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 -~----------~----~----~----~------~----~------~--~---
Gioele Barabucci wrote:> Hello, > > I have some constants that I need to share in almost all the pieces of > my application. So I decided to put them in ApplicationHelper. From what > I understand, ApplicationHelper is used to store helpers available to > the whole application. > > Somehow my models and my views are unable to access the constants > defined in ApplicationHelper. My workaround for models is to ''include > ApplicationHelper'' inside the model declaration. For views I haven''t > found a working solution aside copy''n''pasting these constants inside the > views. > > What is the correct way to use ApplicationHelper and make constants > available to the entire application? > > -- > GioeleI had a similar problem, but it was a common function. So in the models I created global.rb: class Global def self.frog return "Hello world" end end Then to use it anywhere I enter Global.frog -- 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 -~----------~----~----~----~------~----~------~--~---