So I'm trying to make this into a link_to link:
<a class="dropdown-toggle" data-toggle="dropdown" href="#">Sign-In <b class="caret"></b></a>
I have this so far, but can't figure out how to handle the <b class="caret"></b>
. I have tried a do block at the end of the link_to
, but only got an error.
<%= link_to "Sign-In", new_user_session_path, :class => "dropdown-toggle", :data => {:toggle=>"dropdown"} %>
I've just started learning Rails, and have searched around (including reading the RoR API docs) but have got nothing to work. Thanks for the help!
The link_to
that you provided is alright in terms of context.
Let me tell you what it is upto:
This is the link that you mentioned:
<%= link_to "Sign-In", new_user_session_path, :class => "dropdown-toggle", :data => {:toggle=>"dropdown"} %>
This is the corresponding html link formed by the above link_to:
<a href="users/sessions/new" class="dropdown-toggle" data-toggle="dropdown">Sign-In</a>
Now consider this link:
<%= link_to(raw("Sign-In" +("<b class= 'caret'></b>")), new_user_session_path, :class => "dropdown-toggle", :data => {:toggle=>"dropdown"}) %>
The above link will give you the following html link:
<a class="dropdown-toggle" data-toggle="dropdown" href="users/sessions/new">Sign-In<b class= 'caret'></b></a>
Now you are almost close to your result. The only thing is the href.
Ok let's modify the above link_to
a bit with just a change in href path as-
<%= link_to(raw("Sign-In" +("<b class= 'caret'></b>")), "#", :class => "dropdown-toggle", :data => {:toggle=>"dropdown"}) %>
The generated link is now equivalent to what you wanted:
<a href="#" class="dropdown-toggle" data-toggle="dropdown">Sign-In<b class= 'caret'></b></a>
If you provide a block, you omit the first argument (normally the content of the a tag) and it will be replaced by what the block yields.
<%= link_to new_user_session_path, :class => "dropdown-toggle", :data => {:toggle=>"dropdown"} do %>
Sign-In <b class="caret"></b>
<% end %>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With