Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

Ruby

Hyperlink word inside a “Post” text field in Rails 4

I am building a blog and looking for a way to hyperlink words in my posts. I have used auto_html for videos and photos, but I do not like the aesthetics of the links as they must contain the http:// in order to be recognized by the gem.

Does anyone know of a gem, a way to insert HTML into the "Post" text field, or code i can add to my post.rb model to hyperlink words?

1 Answer

Here are two ideas...

If you want to use HTML in your Post field, use the html_safe method.

Put something like this in your views:

  <%= @post.body.html_safe =>

Another idea is to use Markdown for writing your blog posts. It is a bit more work to get Markdown rendering working, but if you like writing in Markdown - it is well worth it.

There is a succinct tutorial for using Markdown in Rails at this location: http://richonrails.com/articles/rendering-markdown-with-redcarpet

I have not completed the Markdown tutorial, but I skimmed through it and it looks accurate. If you decide to go that route, and get stuck, I'd be happy to try and help.