Images and <div> pulled from Rails model -


when view source code site such www.dribble.com see each image has it's own <div>, when pull images rails models code such as:

<div class="article">  <% @articles.in_groups_of(5, false).each |group| %>   <div class="row">    <% group.each |article| %>     <div class="col-md-2">        <%= link_to image_tag(article.artwork.thumb), ?? %>        <%= sanitize(article.title) %>     </div>    <% end %>   </div>  <% end %> </div>  <%= will_paginate @articles %> 

the images come single <div>. instagram source code shows user's 9 photos in home page single <div> , instagram , photo layout looks similar images plucked rails model.

does mean not possible pull images rails model , make them fancy/responsive way see on www.dribble.com ?

also, other languages allow make photos responsive/fancy provide ability pull images models or site www.dribble.com have manually code each <div>/image? ask because in every beginner's tutorial see java/html hand writing imgs code, haven't seen examples pulling images models/databases way in rails tutorials.

as bonus, in above code trying figure out 2 things:

  1. rb.6 how create link id of article, "example.com/article/1"

  2. rb.6 how create link url attached in :title column. title entered form under title column <a href="http://cnn.com">foo bar</a> , sanitized in rb.7 "foo bar".

thank you.

you're confused role of rails / css.


we use paperclip our images; doesn't matter whether you're using or carrierwave - pattern same.

images saved on hard drive (either locally on web server, or externally on s3 etc), paperclip / carrierwave store references images in db. when call image through rails, you're pulling image.jpg data through db & hdd.

the stylization of image entirely you:

<%= content_tag :div, class: "article" %>   <% @articles.in_groups_of(5, false).each |group| %>     <%= content_tag :div, class:"row %">       <% group.each |article| %>         <div class="col-md-2">           <%= link_to image_tag(article.artwork.thumb), article %>           <%= sanitize(article.title) %>         </div>       <% end %>     <% end %>   <% end %> <% end %> 

since above looks messy, may wish adopt haml:

.class   - @articles.in_groups_of(5, false).each |group|     .row       - group.each |article|         .col-md-2           = link_to image_tag(article.artwork.thumb), article            = sanitize article.title 

how create link id of article

you should read link_to - have pass "output" followed url. rails uses resourceful routing structure, you'll able pass article object directly:

link_to "text", article                #-> <a href="example.com/articles/[[id]]">text</a> link_to "text", articles_path(article) #-> <a href="example.com/articles/[[id]]">text</a> 

this considers have following set in routes:

#config/routes.rb resources :articles 

--

how create link url attached in :title column

not sure you're asking; if want pass block link_to, use:

= link_to article   = image_tag article.artwork.thumb   = sanitize article.title 

... yield:

<a href="http://example.com/articles/[[id]]">   <img src="..." />   title </a> 

make them fancy/responsive

entirely css issue.


Comments

Popular posts from this blog

sublimetext3 - what keyboard shortcut is to comment/uncomment for this script tag in sublime -

java - No use of nillable="0" in SOAP Webservice -

ubuntu - Laravel 5.2 quickstart guide gives Not Found Error -