<h3>Social Media Handles: (<%=link_to 'Seel All Social Media', influencer_influencer_social_media_handles_path(#influencer)%>)</h3>
<ul>
<% #influencer.influencer_social_media_handles.each {|social_media_handles| %>
<li><strong>Social Media Name:</strong> <%=social_media_handles.social_media_name%><br />
<%=link_to(social_media_handles.social_media_handle) %>
</li>
<% } %>
</ul>
This <%=link_to(social_media_handles.social_media_handle) %> is actually a link to a twitter page i.e http://twitter.com/#!/SrBachchan. But when I click on it nothing happens. How can I make this link working so it will take me to a twitter page.
Thanks
Please take a look here for a comprehensive usage of link_to tag in rails.
<%= link_to 'Twitter Profile', social_media_handles.social_media_handle %>
The method is link_to(:body, :url, :options)
So, you should:
<%= link_to 'Twitter Profile', social_media_handles.social_media_handle %>
Assuming that social_media_handles.social_media_handle returns "http://twitter.com/#!/SrBachchan" that will generate:
Twitter Profile
Related
I am using ruby 2 and rails 4. I want to add http link into image link in rails. How can I create that?
My codes:
<% for g in #pictures %>
<%= link_to image_tag g.pic_url, class: "img-responsive img-thumbnail" %>
<% end %>
I want to create something like below using rails.
<img src="/assets/image_001.jpg" class="img-responsive img-thumbnail">
Please share with me if any one has any idea.
The link_to helper can take a block of code, allowing you to do something like the following:
<% for g in #pictures %>
<%= link_to g.pic_url do %>
<%= image_tag g.pic_url, class: "img-responsive img-thumbnail" %>
<% end %>
<% end %>
More info on the link_to helper can be found by looking through the Rails API documentation.
Hope it helps!
my solution:
<%= link_to root_path do %>
<%= image_tag "image.jpg", class: "some css class here" %>
<% end %>
link_to take first argument as link's name and second argument is as url. in your code you have not assign url option. Change it as below
Try:
<%= link_to (image_tag(g.pic_url, class: "img-responsive img-thumbnail"), g.pic_url) %>
Ruby on Rails using link_to with image_tag
REST noob here:
I'm using the code from ryan bates rails cast #241
http://railscasts.com/episodes/241-simple-omniauth
I can authenticate with my user just fine....
Now I want to display the last tweet I made on the views/articles/index.html.erb page....
I want to just want to display the data from this REST api thing..."https://dev.twitter.com/docs/api/1.1/get/statuses/home_timeline"
How do I change this code in the most simplest way?
<% title "Articles" %>
<div id="articles">
<!-- TODO grab my tweets with GET Statuses/home_timeline -->
<% for article in #articles %>
<h2>
<%= link_to article.name, article %>
<span class="comments">(<%= pluralize(article.comments.size, 'comment') %>)</span>
</h2>
<div class="created_at">on <%= article.created_at.strftime('%b %d, %Y') %></div>
<div class="content"><%= simple_format(article.content) %></div>
<% end %>
</div>
<p><%= link_to "New Article", new_article_path %></p>
Thank you for help.
You should take a loot at twitter gem: http://sferik.github.com/twitter/
You can grab a user's timeline like: timeline = Twitter.user_timeline( twitter_username )
My app showing thumbnails, but if I click the thumbail, its downloaded, not showed up. How its work? link_to image_tag('lorem'), image_tag('lorem_big')?
<% for photo in #article.attachments %>
<%= link_to image_tag('dinamic/'+photo.id.to_s+'/'+'thumbs_'+photo.image_file_name), "#{request.env["HTTP_HOST"]}/public/images/dinamic/"+photo.id.to_s+"/"+"originals_"+photo.image_file_name, :class => 'single_image'%>
<% end %>
Have you tried different browsers?
Try to capture HTTP communication how your app server sets Content-Disposition header attribute.
If you cannot control your server, you can do minicontroller which will render one tag with that image :)
<% for photo in #static.attachments %>
<a id="single_image" href="<%= image_path("dinamic/"+photo.id.to_s+"/"+"originals_"+photo.image_file_name) %>" > <%= image_tag('dinamic/'+photo.id.to_s+'/'+'thumbs_'+photo.image_file_name) %> </a>
<% end %>
Image_path solved this issue.
How would i use
<% link_to (post) do %>
<%= pluralize(post.comments.size,'comment') %>
<% end %>
to link to a div, for example the url:
http://myblog.com/post/21#mydiv
i need to do this so that when a user clicks the comments link they are taken to the comments div on the page. This would also be useful to use to redirect users to the comment they have just posted like so:
http://myblog.com/post/21#comment_id
thanks alot!
You can use:
<% link_to(post, :anchor => 'mydiv') do %>
<%= pluralize(post.comments.size,'comment') %>
<% end %>
link_to API documentation
link_to(post, pluralize(post.comments.size,'comment'), :anchor => "mydiv")
How do I wrap a link around view code? I can't figure out how to pass multiple lines with ruby code to a single link_to method. The result I am looking for is that you click the column and get the show page:
<div class="subcolumns">
<div class="c25l">
<div class="subcl">
<%= image_tag album.photo.media.url(:thumb), :class => "image" rescue nil %>
</div>
</div>
<div class="c75r">
<div class="subcr">
<p><%= album.created_at %></p>
<%= link_to h(album.title), album %>
<p><%= album.created_at %></p>
<p><%= album.photo_count %></p>
</div>
</div>
</div>
link_to takes a block of code ( >= Rails 2.2) which it will use as the body of the tag.
So, you do
<%= link_to(#album) do %>
html-code-here
<% end %>
But I'm quite sure that to nest a div inside a a tag is not valid HTML.
EDIT: Added = character per Amin Ariana's comment below.
Also, this may be an issue for some:
Make sure to write <%= if you are doing a simple link with code in it instead of <%.
e.g.
<%= link_to 'some_controller_name/some_get_request' do %>
Hello World
<% end %>
For older Rails versions, you can use
<% content_tag(:a, :href => foo_path) do %>
<span>Foo</span>
<% end %>
You can use link_to with a block:
<% link_to(#album) do %>
<!-- insert html etc here -->
<% end %>
A bit of a lag on this reply I know -- but I was directed here today, and didn't find a good answer. The following should work:
<% link_to raw(html here), #album %>