is there a ways to get a unique id (number) which is unique for each executing page ... sometimes i need a unique number to identify html elements in order to access them later with javascript. i would like to call <div id="container_<%= unique_id %>"> some hints? -- 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 -~----------~----~----~----~------~----~------~--~---
You could always use the controller and action name. First, make a helper method within helpers/application_helper.rb def page_id "#{controller.controller_name}_#{controller.action_name}" end If you call /projects/new this will contain "projects_new" That would be pretty unique for a page. I''m sure there are other ways to do that though. Good luck! On Dec 17, 2007 10:41 AM, Michal Gabrukiewicz < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > is there a ways to get a unique id (number) which is unique for each > executing page ... sometimes i need a unique number to identify html > elements in order to access them later with javascript. > > i would like to call <div id="container_<%= unique_id %>"> > > some hints? > -- > 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 -~----------~----~----~----~------~----~------~--~---
thanks brian for the quick response, but what i am looking for is a unique id (per page) ... so whenever i call unique_id it should be a unique id .. this would be just unique per action. i need e.g. <div id="container_<%= unique_id %>"></div> <div id="container_<%= unique_id %>"></div> <div id="container_<%= unique_id %>"></div> this should produce something like.. <div id="container_1"></div> <div id="container_2"></div> <div id="container_3"></div> important is that the ids are unique per page so i can call them with javascript -- 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 Dec 17, 2007, at 11:08 AM, Michal Gabrukiewicz wrote:> > thanks brian for the quick response, but what i am looking for is a > unique id (per page) ... so whenever i call unique_id it should be a > unique id .. this would be just unique per action. > > i need e.g. > > <div id="container_<%= unique_id %>"></div> > <div id="container_<%= unique_id %>"></div> > <div id="container_<%= unique_id %>"></div> > > this should produce something like.. > > <div id="container_1"></div> > <div id="container_2"></div> > <div id="container_3"></div> >You could possibly do something like this: def unique_id key = controller_name.to_sym if !session[key] session[key] = 0 end session[key] += 1 return session[key] end Peace, Phillip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
thats possible but using a session for such common task is a bit overkill for me .. there must be an easier solution ... -- 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 -~----------~----~----~----~------~----~------~--~---
Sure there is. You just need an instance variable. def unique_id @unique_id ||= 0 #use what you have in instance, or set it to 0 @unique_id += 1 end On Dec 17, 2007 11:36 AM, Michal Gabrukiewicz < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > thats possible but using a session for such common task is a bit > overkill for me .. there must be an easier solution ... > -- > 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 -~----------~----~----~----~------~----~------~--~---
By the way, if you''re doing this in a loop, there''s an easier way. <% @projects.each_with_index do |@project <%7C@project>, index| %> <div id="container_<%=index %>"> </div> <% end %> Or use the id of the class <% @projects.each do |@project <%7C@project>| %> <div id="container_<%=@project.id %>"> </div> <% end %> or if you''re using Rails 2.0 <% @projects.each do |@project <%7C@project>| %> <% div_for @project do %> <% end %> <% end %> On Dec 17, 2007 12:43 PM, Brian Hogan <bphogan-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Sure there is. You just need an instance variable. > > def unique_id > @unique_id ||= 0 #use what you have in instance, or set it to 0 > @unique_id += 1 > end > > On Dec 17, 2007 11:36 AM, Michal Gabrukiewicz < > rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote: > > > > > thats possible but using a session for such common task is a bit > > overkill for me .. there must be an easier solution ... > > -- > > 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 Dec 17, 2007, at 12:43 PM, Brian Hogan wrote:> Sure there is. You just need an instance variable. > > def unique_id > @unique_id ||= 0 #use what you have in instance, or set it to 0 > @unique_id += 1 > end >Heh, don''t know why I was thinking that the unique_id value would need to survive page changes. The instance variable is a much better idea. Peace, Phillip --~--~---------~--~----~------------~-------~--~----~ 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 guess you need Simply Helpful Plugin. It is now part of Rails 2.0. Check out this link: http://www.juixe.com/techknow/index.php/2007/04/03/simply-helpful-rails-plugin/ On Dec 17, 2007 8:41 AM, Michal Gabrukiewicz < rails-mailing-list-ARtvInVfO7ksV2N9l4h3zg@public.gmane.org> wrote:> > is there a ways to get a unique id (number) which is unique for each > executing page ... sometimes i need a unique number to identify html > elements in order to access them later with javascript. > > i would like to call <div id="container_<%= unique_id %>"> > > some hints? > -- > 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 -~----------~----~----~----~------~----~------~--~---
thanks brian .. thats exactly what i was looking for .. i tried quite the same but it didnt work .. module ApplicationHelper @unique_id = 0 def unique_id @unique_id += 1 end end this didnt work because a module cannot have an instance variable ... cause the helpers gets mixed in somehow.. thanks for your help .. Brian Hogan wrote:> Sure there is. You just need an instance variable. > > def unique_id > @unique_id ||= 0 #use what you have in instance, or set it to 0 > @unique_id += 1 > end > > On Dec 17, 2007 11:36 AM, Michal Gabrukiewicz <-- 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 -~----------~----~----~----~------~----~------~--~---