Hi all, I am looking to implement a tabbed interface. The tabs are mere link_to links in the template. All i need to do is, check if a particular tab has been selected and if it has been selected, set the :id attribute to ''current''. The css code will take care of the rest. I know the css works because when i explicitly set the :id => ''current without any conditions, it shows in the browser. I have however tried many variations and all are throwing me syntax errors. Hope someone can give me the right syntax for this or at least show a better way of implementing this. <%= link_to ''Companies'', companies_path(), :id=>"current" unless controller.controller_name != ''Companies'' %> <%= link_to ''Companies'', companies_path(), if controller.controller_name == ''Companies'' :id=>"current" end%> <%= link_to ''Companies'', companies_path(), if controller.controller_name != ''Companies'' :id=>"current" %> <%= link_to ''Companies'', companies_path(), if current_page? (:controller=> ''Companies'') :id=>"current" end%> I have seen the rails widget s plugin for tabbed interface and it just seems as too much code for something so simple. --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Erol Fornoles
2008-Oct-11 05:21 UTC
Re: Conditionally assigning html id to link_to (tabbed interface)
Vinay wrote:> Hi all, > I am looking to implement a tabbed interface. The tabs are mere > link_to links in the template. All i need to do is, check if a > particular tab has been selected and if it has been selected, set > the :id attribute to ''current''. The css code will take care of the > rest. I know the css works because when i explicitly set the :id => > ''current without any conditions, it shows in the browser. > I have however tried many variations and all are throwing me syntax > errors. Hope someone can give me the right syntax for this or at least > show a better way of implementing this. > > <%= link_to ''Companies'', companies_path(), :id=>"current" unless > controller.controller_name != ''Companies'' %> > <%= link_to ''Companies'', companies_path(), if > controller.controller_name == ''Companies'' :id=>"current" end%> > <%= link_to ''Companies'', companies_path(), if > controller.controller_name != ''Companies'' :id=>"current" %> > <%= link_to ''Companies'', companies_path(), if current_page? > (:controller=> ''Companies'') :id=>"current" end%> > > I have seen the rails widget s plugin for tabbed interface and it just > seems as too much code for something so simple.Creating your own tab link helper ought to ease things up: def tab_link_to(name, options = {}, html_options = {}) html_options.merge!({ :id => ''current'' }) if current_page?(options) link_to name, options, html_options end Which you could then use in your view: <% tab_link_to ''Companies'', companies_path %> --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Vinay
2008-Oct-11 09:05 UTC
Re: Conditionally assigning html id to link_to (tabbed interface)
@Erol, Thank you so much! I have been letting this bug me for a couple of days now and to see your simple solution working is an amazing pick-me- up! :) I think its the simplest tabbed interface code one could hope for. On Oct 11, 10:21 am, Erol Fornoles <erol.forno...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Vinay wrote: > > Hi all, > > I am looking to implement a tabbed interface. The tabs are mere > > link_to links in the template. All i need to do is, check if a > > particular tab has been selected and if it has been selected, set > > the :id attribute to ''current''. The css code will take care of the > > rest. I know the css works because when i explicitly set the :id => > > ''current without any conditions, it shows in the browser. > > I have however tried many variations and all are throwing me syntax > > errors. Hope someone can give me the right syntax for this or at least > > show a better way of implementing this. > > > <%= link_to ''Companies'', companies_path(), :id=>"current" unless > > controller.controller_name != ''Companies'' %> > > <%= link_to ''Companies'', companies_path(), if > > controller.controller_name == ''Companies'' :id=>"current" end%> > > <%= link_to ''Companies'', companies_path(), if > > controller.controller_name != ''Companies'' :id=>"current" %> > > <%= link_to ''Companies'', companies_path(), if current_page? > > (:controller=> ''Companies'') :id=>"current" end%> > > > I have seen the rails widget s plugin for tabbed interface and it just > > seems as too much code for something so simple. > > Creating your own tab link helper ought to ease things up: > > def tab_link_to(name, options = {}, html_options = {}) > html_options.merge!({ :id => ''current'' }) if current_page?(options) > link_to name, options, html_options > end > > Which you could then use in your view: > > <% tab_link_to ''Companies'', companies_path %>--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Rob Biedenharn
2008-Oct-11 14:41 UTC
Re: Conditionally assigning html id to link_to (tabbed interface)
You might also want to look at link_to_unless_current (and perhaps its source code) to see how you might change your helper (or abandon it altogether in some cases). -Rob On Oct 11, 2008, at 5:05 AM, Vinay wrote:> > @Erol, > Thank you so much! I have been letting this bug me for a couple of > days now and to see your simple solution working is an amazing pick- > me- > up! :) > I think its the simplest tabbed interface code one could hope for. > > > On Oct 11, 10:21 am, Erol Fornoles <erol.forno...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: >> Vinay wrote: >>> Hi all, >>> I am looking to implement a tabbed interface. The tabs are mere >>> link_to links in the template. All i need to do is, check if a >>> particular tab has been selected and if it has been selected, set >>> the :id attribute to ''current''. The css code will take care of the >>> rest. I know the css works because when i explicitly set the :id => >>> ''current without any conditions, it shows in the browser. >>> I have however tried many variations and all are throwing me syntax >>> errors. Hope someone can give me the right syntax for this or at >>> least >>> show a better way of implementing this. >> >>> <%= link_to ''Companies'', companies_path(), :id=>"current" unless >>> controller.controller_name != ''Companies'' %> >>> <%= link_to ''Companies'', companies_path(), if >>> controller.controller_name == ''Companies'' :id=>"current" end%> >>> <%= link_to ''Companies'', companies_path(), if >>> controller.controller_name != ''Companies'' :id=>"current" %> >>> <%= link_to ''Companies'', companies_path(), if current_page? >>> (:controller=> ''Companies'') :id=>"current" end%> >> >>> I have seen the rails widget s plugin for tabbed interface and it >>> just >>> seems as too much code for something so simple. >> >> Creating your own tab link helper ought to ease things up: >> >> def tab_link_to(name, options = {}, html_options = {}) >> html_options.merge!({ :id => ''current'' }) if current_page?(options) >> link_to name, options, html_options >> end >> >> Which you could then use in your view: >> >> <% tab_link_to ''Companies'', companies_path %> > >--~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
Vinay
2008-Oct-11 16:48 UTC
Re: Conditionally assigning html id to link_to (tabbed interface)
Thank you Rob. I actually DID come across these helpers when i was searching around for solutions. These though provide the link conditionally. If the condition is not satisfied, the link itself does not exist, it only renders text. But i need all the links to exist. And only the CSS id to change conditionally. For which the code above worked like a charm. Thanks again for your input! On Oct 11, 7:41 pm, Rob Biedenharn <R...-xa9cJyRlE0mWcWVYNo9pwxS2lgjeYSpx@public.gmane.org> wrote:> You might also want to look at link_to_unless_current (and perhaps its > source code) to see how you might change your helper (or abandon it > altogether in some cases). > > -Rob > > On Oct 11, 2008, at 5:05 AM, Vinay wrote: > > > > > @Erol, > > Thank you so much! I have been letting this bug me for a couple of > > days now and to see your simple solution working is an amazing pick- > > me- > > up! :) > > I think its the simplest tabbed interface code one could hope for. > > > On Oct 11, 10:21 am, Erol Fornoles <erol.forno...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote: > >> Vinay wrote: > >>> Hi all, > >>> I am looking to implement a tabbed interface. The tabs are mere > >>> link_to links in the template. All i need to do is, check if a > >>> particular tab has been selected and if it has been selected, set > >>> the :id attribute to ''current''. The css code will take care of the > >>> rest. I know the css works because when i explicitly set the :id => > >>> ''current without any conditions, it shows in the browser. > >>> I have however tried many variations and all are throwing me syntax > >>> errors. Hope someone can give me the right syntax for this or at > >>> least > >>> show a better way of implementing this. > > >>> <%= link_to ''Companies'', companies_path(), :id=>"current" unless > >>> controller.controller_name != ''Companies'' %> > >>> <%= link_to ''Companies'', companies_path(), if > >>> controller.controller_name == ''Companies'' :id=>"current" end%> > >>> <%= link_to ''Companies'', companies_path(), if > >>> controller.controller_name != ''Companies'' :id=>"current" %> > >>> <%= link_to ''Companies'', companies_path(), if current_page? > >>> (:controller=> ''Companies'') :id=>"current" end%> > > >>> I have seen the rails widget s plugin for tabbed interface and it > >>> just > >>> seems as too much code for something so simple. > > >> Creating your own tab link helper ought to ease things up: > > >> def tab_link_to(name, options = {}, html_options = {}) > >> html_options.merge!({ :id => ''current'' }) if current_page?(options) > >> link_to name, options, html_options > >> end > > >> Which you could then use in your view: > > >> <% tab_link_to ''Companies'', companies_path %>--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---
Youssef Chaker
2008-Oct-11 22:43 UTC
Re: Conditionally assigning html id to link_to (tabbed interface)
check this out: http://wiki.rubyonrails.org/rails/pages/Tabnav On Oct 11, 12:42 am, Vinay <yourstruly.vi...-Re5JQEeQqe8AvxtiuMwx3w@public.gmane.org> wrote:> Hi all, > I am looking to implement a tabbed interface. The tabs are mere > link_to links in the template. All i need to do is, check if a > particular tab has been selected and if it has been selected, set > the :id attribute to ''current''. The css code will take care of the > rest. I know the css works because when i explicitly set the :id => > ''current without any conditions, it shows in the browser. > I have however tried many variations and all are throwing me syntax > errors. Hope someone can give me the right syntax for this or at least > show a better way of implementing this. > > <%= link_to ''Companies'', companies_path(), :id=>"current" unless > controller.controller_name != ''Companies'' %> > <%= link_to ''Companies'', companies_path(), if > controller.controller_name == ''Companies'' :id=>"current" end%> > <%= link_to ''Companies'', companies_path(), if > controller.controller_name != ''Companies'' :id=>"current" %> > <%= link_to ''Companies'', companies_path(), if current_page? > (:controller=> ''Companies'') :id=>"current" end%> > > I have seen the rails widget s plugin for tabbed interface and it just > seems as too much code for something so simple.--~--~---------~--~----~------------~-------~--~----~ 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@googlegroups.com For more options, visit this group at http://groups.google.com/group/rubyonrails-talk?hl=en -~----------~----~----~----~------~----~------~--~---