Put Haml Tags Inside Link_To Helper

How to add HTML code into a link_to tag in rails?

You can pass a block to the link_to helper

<%= link_to dasharea_signout_path, method: "delete", id: "adminsignout" do %>
<i class="fa fa-tasks"></i>
<span>Signup</span>
<% end %>

The block content will be wrapped in the link tag.

Insert an HTML element inside the link_to erb tag?

You may need to make sure relative paths work correctly...

<li>
<%= link_to 'home' do %>
<%= image_tag('../icons/home', class: "../nav-img") %>
<span>Home</span>
<% end %>
</li>

Also, are you using turbolinks?

How to translate i tag of html into rails' link_to helper?

You can recreate the above link by using link_to's block format, like so:

<%= link_to "#" do %>
<i class="fa fa-twitter"></i>
<% end %>

Hope it helps!

put haml tags inside link_to helper

You should use block

= link_to "path/to/page.html" do
Other page
%span.icon Arrow

Embedded HTML in link_to body in Rails

Try it this way

<%= link_to(raw("a <strong>strong</strong> link"),{:pics => true},{ :class => 'highlight'})  %>

Rails link_to - add string to a tag rather than an attribute

I wasn't able to find a direct way to fix this. So i had to get rid of the link_to and put my ruby code in the href. Which might look something like this

    <a href= "<%= edit_password_url(@resource, :reset_password_token => @token) %>"  mc:disable-tracking> Change my password</a>

How to use link_to that has an i tag inside it?

The first argument of the 'link_to' helper should not be provided with a 'do' block as it will override the block you pass to it. If you provide one (even an empty string) as you have then it uses that instead, so remove the first argument as so:

<%= 
link_to controller: "events", action: "edit", id: event.id do
%>
<i class="glyphicon glyphicon-edit"></i>
<% end %>

Ruby on rails raw tag inside a link_to

From the official Rails raw documentation:

This method outputs without escaping a string. Since escaping tags is now default, this can be used when you don't want Rails to automatically escape tags. This is not recommended if the data is coming from the user's input.

It's not a good practice to use raw because it bypasses the default Rails input sanitization. Use it only if you know what you are doing.

If you need to use raw HTML inside the link to, you can also pass it as a block.

<%= link_to root_url do %>
<span>My link</span>
<% end %>

Another alternative is to use the Rails helpers which sanitizes the input.

<%= link_to content_tag(:span, "Unsafe input"), root_url %>

How to use the tags and classes in link_to helper

You can pass a block to link_to:

<%= link_to retailer_my_stations_path, class: 'dropdown-collapse' do %>
<i class='icon-edit'></i>
<span>My Stations</span>
<% end %>

You can also create a helper method for this.

Rails link_to with complex HTML inside

This looks like a good candidate for the block form of link_to.

<%= link_to event_path(fevent), class: "item-over" do %>
# complex HTML
<% end %>


Related Topics



Leave a reply



Submit