Right now I have two controllers: courses_controller.rb events_controller.rb They each, of course, have their own helpers: courses_helper.rb events_helper.rb Is it possible to create a helper method with the same name in these two helpers such that they are called by the corresponding view? Basically I want: <%= meets_on Schedule.find(:first) %> in courses/index.html.erb to call meets_on in courses_helper.rb and <%= meets_on Schedule.find(:first) %> in events/index.html.erb to call meets_on in events_helper.rb. I thought that''s what would happen, but it turns out that the meets_on method from events_helper.rb gets called all the time. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
The helpers are unique to the controllers. Two methods defined in two helpers should not conflict with or override each other. Are you perhaps including EventsHelper in courses? On Dec 21, 2007 5:06 PM, vince <sthapit-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> > Right now I have two controllers: > > courses_controller.rb > events_controller.rb > > They each, of course, have their own helpers: > > courses_helper.rb > events_helper.rb > > Is it possible to create a helper method with the same name in these > two helpers such that they are called by the corresponding view? > > Basically I want: > > <%= meets_on Schedule.find(:first) %> in courses/index.html.erb to > call meets_on in courses_helper.rb and > > <%= meets_on Schedule.find(:first) %> in events/index.html.erb to > call meets_on in events_helper.rb. > > I thought that''s what would happen, but it turns out that the meets_on > method from events_helper.rb gets called all the time. > > >-- Ryan Bigg http://www.frozenplague.net --~--~---------~--~----~------------~-------~--~----~ 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 could have sworn that helpers are unique to controllers too. To
test it, I created a new project from scratch with just two
controllers for courses and events that created two helpers
courses_helper.rb and events_helper.rb. I put in a very simple method
in each:
courses_helper.rb -
module CoursesHelper
def my_helper
"hello courses"
end
end
events_helper.rb -
module EventsHelper
def my_helper
"hello events"
end
end
Then in views/courses/index.html.erb I put in just one line -
<%= my_helper %>
Now when I go to http://localhost:3000/courses I see this:
hello events
Can someone tell me what I''m doing wrong? I put up the sample project
here -
http://brainassembly.org/helper_trouble
The 3 files I mentioned above are here -
http://brainassembly.org/helper_trouble/app/views/courses/index.html.erb
http://brainassembly.org/helper_trouble/app/helpers/courses_helper.rb
http://brainassembly.org/helper_trouble/app/helpers/events_helper.rb
The whole project can be downloaded here -
http://brainassembly.org/helper_trouble.zip
Thanks for any help!
On Dec 21, 1:45 am, "Ryan Bigg"
<radarliste...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org>
wrote:> The helpers are unique to the controllers. Two methods defined in two
> helpers should not conflict with or override each other. Are you perhaps
> including EventsHelper in courses?
>
> On Dec 21, 2007 5:06 PM, vince
<stha...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:
>
>
>
>
>
> > Right now I have two controllers:
>
> > courses_controller.rb
> > events_controller.rb
>
> > They each, of course, have their own helpers:
>
> > courses_helper.rb
> > events_helper.rb
>
> > Is it possible to create a helper method with the same name in these
> > two helpers such that they are called by the corresponding view?
>
> > Basically I want:
>
> > <%= meets_on Schedule.find(:first) %> in courses/index.html.erb
to
> > call meets_on in courses_helper.rb and
>
> > <%= meets_on Schedule.find(:first) %> in events/index.html.erb
to
> > call meets_on in events_helper.rb.
>
> > I thought that''s what would happen, but it turns out that the
meets_on
> > method from events_helper.rb gets called all the time.
>
> --
> Ryan Bigghttp://www.frozenplague.net
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---
You may want to look at "application.rb" because it will answer your question. Note the line in that file: helper :all # include all helpers, all the time You might guess what that does ;) Remove that line and all will be well. -- 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 -~----------~----~----~----~------~----~------~--~---
haha. thanks. it works now :) i guess i was thinking that something like this would be in application_helper.rb but good to know! On Dec 22, 2:09 pm, Nathan Esquenazi <rails-mailing-l...@andreas- s.net> wrote:> You may want to look at "application.rb" because it will answer your > question. Note the line in that file: > > helper :all # include all helpers, all the time > > You might guess what that does ;) > > Remove that line and all will be well. > -- > 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 -~----------~----~----~----~------~----~------~--~---