Extracting view code to helpers

Helper is used to abstract view methods. It is designed for using in view.

app/helpers/photos_helper.rb file:

1module PhotoHelper
2  def absolute_photo_url(photo, style=nil)
3    request.protocol + request.host_with_port + photo.file.url(style)
4  end

So now, the photo url can be like this:

1json.thumb_url absolute_photo_url(photo, :thumb)

What’s next? We’re going to take a look at “Partial json views”.

overlaied image when clicked on thumbnail

Makzan | Ruby on rails 101 | Table of Content