We are upgrading rails from 2.3.5 to 3.2.1. While upgrading we are getting issue with link_to method.We have the following code snippet.
link_to( name, path_options, html_options, *params )
Here name is:
<span class='bmark_link_tag'><img alt="Post this blog to Stumbleupon" src="/images/png/stumble.png" /> Stumbleupon</span>
But while rendering it is directly displaying the above name value instead of displaying image in UI.
Could you please help us on this ASAP.
You can use image_tag in link_to as,
<%= link_to image_tag("images/png/stumble.png", :alt=>"Post this blog to Stumbleupon", :class=>"bmark_link_tag")+"Stumbleupon", your_path %>
Related
I need to remove <a> tag from rails link_to method. Here is current code and result:
<%= link_to "ESP", :locale=>'es'%>
<a href="/es/blog/crazy_page">ESP</p>
Here is my desired outcome:
/es/blog/crazy_page
Reason I need this is so I could make "alternate" link tag in header for each language. Can't seem to find this anywhere.
Use url_for method
<%= url_for(:locale => 'es') %>
Run a page created in rails 4.1 from the tag (html) code that acontinuacion I detail, for every time I Click on the menu I double the url:
pages / pages / pages (so in doubles in the url):
<li >
<a href="/pages">
<span>Paginas</span>
</a>
</li>
As execute a page in rails 4.1 from the tag ?????
Use link helper
<%= link_to pages_path do %>
<span>Paginas</span>
<% end %>
I'm trying to create a link to a specific page section id.
It's something like the bellow html, but I want to use rails instead...
<a id="tips">Useful Tips Section</a>
Visit the Useful Tips Section
How can I specify the "#tips" in the link_to function? Or should I create a specific route? How?
Thanks in advance
You can use
<%= link_to "Visit the Useful Tips Section", action_path(anchor: tips) %>
In routes you can specify the action_path.
As per Rails API docs you should do the above way, please refer this, and find below example :
link_to "Comment wall", profile_path(#profile, anchor: "wall")
# => Comment wall
try using link_to
<%= link_to "Visit the Useful Tips Section","/#tips" %>
assuming you are linking to an id on the same page
<%= link_to('new button', action: 'login' , class: "text-center") %>
created an anchor tag for login.html i.g
new button
and for
new button
use
<%= link_to('new button', controller: 'admin',
action: 'login' , class: "text-center") %>
My goal is to customize the tags for blog posts in the Refinery CMS. By default they are not styled. I added some styling just to test that I was making changes to the right areas (yes I know it is ugly).
But my goal intent is to get them in a format similar to what I have on my own blog.
Refinery is adding a comma after each tag. What should I modify in the html or css to not add the commas?
app/views/refinery/blog/shared/_tags.html.erb
<% if #tags.any? %>
<h2>Tag Cloud</h2>
<nav id='tags'>
<% tag_cloud(#tags, %w(tag1 tag2 tag3 tag4)) do |tag, css_class| %>
<%= link_to tag.name, refinery.blog_tagged_posts_path(tag.id, tag.name.parameterize), :class => css_class %>
<% end %>
</nav>
<% end %>
The tag_cloud method is a method found in the acts-as-taggable-on library that the refinerycms-blog extension uses. More information can be found out about it in the readme for the library.
This is the code that I have for my posts/index.html.erb file:
<!--
Iterate over each post in list format
-->
<% #posts.each do |post| %>
<ul class="posts">
<!--
Link to article, display date created, show edit, delete links if logged in
-->
<li><%= link_to "#{post.title}".html_safe, post, id: "article" %></li>
<li id="date"> <%= post.created_at.strftime("%B %Y") %></li>
<% if logged_in? %>
<li>
<%= link_to 'Edit', "/editor" + post_path(post), id: "edit_delete", data: {save_url: mercury_update_post_path(post)} %>
<%= link_to 'Delete', post, id: "edit_delete", :method => :delete %>
</li>
<% end %>
</ul>
<% end %>
In my local development and production environments, the associated css stylesheet and html compiles and renders in the browser properly. BUT, when I deploy this code to heroku, it adds some old HTML that I had deleted earlier, as seen in the page source code:
<!--
Iterate over each post in list format
-->
<ul class="posts">
<!--
Link to article, display date created
-->
<li> <a href="/posts/5" id="article"><b>Endurance Exercise is Bad for your Health?</b>
<div><b><br></b></div></a> </li>
<li id="date"> February 2013 </li>
<!--
Show edit, delete links if logged in
-->
</ul>
see the <div><b><br></b></div> tags embedded within the link tag for the article "Endurance Exercise is Bad for your Health?" ... Anyone know why that is being put there when deployed to heroku on production?
This is your culprit. "#{post.title}".html_safe
One of the posts that you are displaying has html tags in its title. It's a bad idea to call .html_safe to anything entered by a user. You should escape that using h(post.title) or sanitize the string first for accepted tags. Look at the sanitize helper