Adding Image icon to a Blog title post

13 views
Skip to first unread message

Elysee Montissol

unread,
Feb 28, 2016, 9:42:35 PM2/28/16
to rubyonra...@googlegroups.com
I created a simple blog and I'm using paperclip to be able to add images
to a Post. I installed the 'themify-icons-rails' gem and what I want to
do is automatically add a picture icon next to the title of a post when
the post has a image that's been uploaded, to show that the post has a
image. I'm guessing I would need a If statement somewhere but I'm fairly
new to rails and I'm not sure where to put it.

<h2 class="ti-gallery"><%= link_to post.title, post %></h2> this adds
the "Ti-gallery" icon to every post.

Any Help will be greatly appreciated, Thank you before hand. Oh and one
more questions, Is rails Video friendly? i can't seem to find any
tutorials on uploading videos to a rails app.

--
Posted via http://www.ruby-forum.com/.

Colin Law

unread,
Feb 29, 2016, 3:53:58 AM2/29/16
to Ruby on Rails: Talk
On 29 February 2016 at 02:41, Elysee Montissol <li...@ruby-forum.com> wrote:
> I created a simple blog and I'm using paperclip to be able to add images
> to a Post. I installed the 'themify-icons-rails' gem and what I want to
> do is automatically add a picture icon next to the title of a post when
> the post has a image that's been uploaded, to show that the post has a
> image. I'm guessing I would need a If statement somewhere but I'm fairly
> new to rails and I'm not sure where to put it.
>
> <h2 class="ti-gallery"><%= link_to post.title, post %></h2> this adds
> the "Ti-gallery" icon to every post.

Assuming that what you want to leave out is the class specification
and assuming that post.image will be nil if there is no image (replace
that with something similar as necessary)
<h2 <%= "class=/"ti-gallery/"" if post.image %> >
<%= link_to post.title, post %>
</h2>

I have split it onto multiple lines to make it easier to read, that
will not affect the displayed page. The result of the code
"class=/"ti-gallery/"" if post.image
will either be the class= string or nil.

Colin

>
> Any Help will be greatly appreciated, Thank you before hand. Oh and one
> more questions, Is rails Video friendly? i can't seem to find any
> tutorials on uploading videos to a rails app.
>
> --
> Posted via http://www.ruby-forum.com/.
>
> --
> You received this message because you are subscribed to the Google Groups "Ruby on Rails: Talk" group.
> To unsubscribe from this group and stop receiving emails from it, send an email to rubyonrails-ta...@googlegroups.com.
> To post to this group, send email to rubyonra...@googlegroups.com.
> To view this discussion on the web visit https://groups.google.com/d/msgid/rubyonrails-talk/050fa96f2643c768b05341ba1eefca74%40ruby-forum.com.
> For more options, visit https://groups.google.com/d/optout.

Elysee Montissol

unread,
Feb 29, 2016, 10:13:22 PM2/29/16
to rubyonra...@googlegroups.com
Thank you, Thank you, Thank you!, removing the nil? actually worked.
Question How friendly is rails with videos, I also want to upload
videos. but can't seem to find any tutorials on doing that.
Reply all
Reply to author
Forward
0 new messages