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:
is there a way to do it, or will i have to do it the old html way?
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:
is there a way to do it, or will i have to do it the old html way?
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: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
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:
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
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:
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
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.
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)
that worked it out! thanks so much. you’ve been a great help.
Alex W. wrote:
Check out the docs for link_to
http://caboo.se/doc/classes/ActionView/Helpers/UrlHelper.html#M006132
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs