is there a way to set the classes and ids of html elements made via helpers. for instance i want to create a link that results in the following html: <a href="index.html" id="current" class="northcrest">Home</a> is there a way to do it, or will i have to do it the old html way? -- 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 -~----------~----~----~----~------~----~------~--~---
> is there a way to set the classes and ids of html elements made via > helpers. for instance i want to create a link that results in the > following html: > > > <a href="index.html" id="current" class="northcrest">Home</a> > > is there a way to do it, or will i have to do it the old html way?<%= link_to ''Home'', ''index.html'', :id => ''current'', :class => ''northcrest'' %> But I doubt you really want to link to ''index.html'' in a rails app... maybe ''/'' or home_url or something like that. -philip --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
hey thanks for the reply. i tried what you suggested. here is the code: <%= link_to "Results", :action => "index", :id => "current", :class => "northcrest" %> and here is the resulting html: <a href="/plugincompare/index/current?class=northcrest">Results</a> my first post was a little off. this is what i''m looking for as a result. same concept: <a href="/plugincompare/index" id="current" class=northcrest">Results</a> -- 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 -~----------~----~----~----~------~----~------~--~---
browner than u wrote:> hey thanks for the reply. i tried what you suggested. here is the > code: > > <%= link_to "Results", :action => "index", :id => "current", :class => > "northcrest" %> > > and here is the resulting html: > > <a href="/plugincompare/index/current?class=northcrest">Results</a> > > my first post was a little off. this is what i''m looking for as a > result. same concept: > > <a href="/plugincompare/index" id="current" > class=northcrest">Results</a>Check out the docs for link_to http://caboo.se/doc/classes/ActionView/Helpers/UrlHelper.html#M006132 Mainly: link_to(name, options = {}, html_options = nil) Now in this littl method, name is what appears for you to click on, options is actually an object which can generate a url, and html_options is a hash of attribute/value pairs added to the resulting html tag. So when you do: link_to "Results", :action => "index", :id => "current", :class => "northcrest" Ruby thinks it is: link_to("Results", {:action => "index", :id => "current", :class => "northcrest"}) All those options are getting wrapped up in the hash that is used to generate the url. You want to pass some of those into the html_options argument. link_to(''Results'', {:action => ''index}, {:id => ''current'', :class => ''northcrest}) This nested brace syntax can be a bit cumbersome. This is one of the many reasons people often used named routes instead. #routes.rb map.results ''results'', :controller => ''results'' #view link_to ''Results'', results_path, :id => ''current'', :class => ''northcrest'' The results_path fills the url portions of the arguments, and the hash you then pass in falls into the "html_options" argument, providing the functionality you want. -- 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 -~----------~----~----~----~------~----~------~--~---
> hey thanks for the reply. i tried what you suggested. here is the > code: > > <%= link_to "Results", :action => "index", :id => "current", :class => > "northcrest" %>oops. <%= link_to "Results", {:action => "index"}, :id => "current", :class => "northcrest" %> (note the {}''s)> > and here is the resulting html: > > <a href="/plugincompare/index/current?class=northcrest">Results</a> > > my first post was a little off. this is what i''m looking for as a > result. same concept: > > <a href="/plugincompare/index" id="current" > class=northcrest">Results</a> > > -- > 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 -~----------~----~----~----~------~----~------~--~---
that worked it out! thanks so much. you''ve been a great help. Alex Wayne wrote:> > Check out the docs for link_to > > http://caboo.se/doc/classes/ActionView/Helpers/UrlHelper.html#M006132 >-- 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 -~----------~----~----~----~------~----~------~--~---